Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoTokenizer, TextIteratorStreamer | |
# Define the models and their configurations | |
model_name = "phi-2" | |
model_configuration = { | |
"toeknizer_kwargs": {'model_id': 'susnato/phi-2', 'prompt_template': 'Instruct:{instruction}\nOutput:'} | |
} | |
# Load the tokenizer | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
tokenizer_kwargs = model_configuration.get("toeknizer_kwargs", {}) | |
# Define the Gradio interface | |
def main(): | |
with gr.Row(): | |
with gr.Column(scale=4): | |
user_text = gr.Textbox( | |
placeholder="Write an email about an alpaca that likes flan", | |
label="User instruction", | |
) | |
model_output = gr.Textbox(label="Model response", interactive=False) | |
performance = gr.Textbox(label="Performance", lines=1, interactive=False) | |
with gr.Column(scale=1): | |
button_clear = gr.Button(value="Clear") | |
button_submit = gr.Button(value="Submit") | |
# Run the Gradio interface | |
iface = gr.Interface(fn=main, inputs=user_text, outputs=model_output, performance=performance, live=True) | |
iface.launch() |