File size: 789 Bytes
c2fc6b8 c7be05a a8bb7b0 c7be05a be336e7 c7be05a 6c338fd c7be05a 6c338fd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from transformers import pipeline
from gradio import Interface
import gradio as gr
# Create a dictionary of models
MODELS = {
"GPT-2": "gpt2",
"mGPT": "ai-forever/mGPT"
}
# Define your function
def generate_and_analyze(model_name, input_text):
# Load the model from the dictionary using the selected model name
model = MODELS[model_name]
text_generator = pipeline('text-generation', model=model)
result = text_generator(input_text, max_length=10, do_sample=True)[0]
return result['generated_text']
# Define your interface
iface = gr.Interface(
fn=generate_and_analyze,
inputs=[
gr.inputs.Dropdown(choices=list(MODELS.keys()), label="Model"),
gr.inputs.Textbox(lines=2, label="Input Text")
],
outputs="text"
)
iface.launch()
|