SinaRp's picture
Update app.py
c5f0901 verified
raw
history blame
1.42 kB
# app.py
import gradio as gr
from transformers import pipeline
def load_question_generator(num_questions):
pipe = pipeline("text2text-generation", model="SinaRp/Question_generator_persian", do_sample=True, top_k=50, top_p=0.95, num_return_sequences=num_questions)
return pipe
def generate_questions(context, num_questions):
try:
generator = load_question_generator(num_questions)
questions = generator(context, max_length=64, num_return_sequences=int(num_questions))
return "\n\n".join([q['generated_text'] for q in 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],
["Machine learning is a subset of artificial intelligence that focuses on the use of data and algorithms to imitate the way that humans learn.", 3]
]
)
if __name__ == "__main__":
iface.launch()