Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
def load_question_generator(): | |
question_generator = pipeline('text2text-generation', | |
model='your-username/your-model-name') | |
return question_generator | |
def generate_questions(context, num_questions=3): | |
try: | |
generator = load_question_generator() | |
questions = [] | |
for _ in range(num_questions): | |
result = generator(context, max_length=64, num_return_sequences=1) | |
questions.append(result[0]['generated_text']) | |
return "\n\n".join(questions) | |
except Exception as e: | |
return f"Error generating questions: {str(e)}" | |
iface = gr.Interface( | |
fn=generate_questions, | |
inputs=[ | |
gr.Textbox(lines=5, label="Enter your text context"), | |
gr.Slider(minimum=1, maximum=5, value=3, step=1, label="Number of questions") | |
], | |
outputs=gr.Textbox(label="Generated Questions"), | |
title="Question Generator", | |
description="Generate questions from your text using AI", | |
examples=[ | |
["The Sun is the star at the center of the Solar System. It is a nearly perfect sphere of hot plasma, heated to incandescence by nuclear fusion reactions in its core.", 2], | |
] | |
) | |
iface.launch() |