solutiontesting / app.py
yuvraj-yadav's picture
Update app.py
e9b7c7d verified
!pip install transformers accelerate gradio
from transformers import pipeline
import gradio as gr
generator = pipeline("text-generation", model="tiiuae/falcon-rw-1b") # Or try flan-t5-base
prompt = """
You are a professor of Discrete Mathematics. Generate an original and creative discrete math question (not copied or templated), suitable for university-level students.
Include only the question. Avoid multiple-choice format.
Topic: Combinatorics
Difficulty: Medium
Question:
"""
response = generator(prompt, max_new_tokens=150)[0]['generated_text']
print(response)
def generate_question(topic, difficulty):
prompt = f"""
You are a professor of Discrete Mathematics. Generate an original and creative discrete math question.
Topic: {topic}
Difficulty: {difficulty}
Question:
"""
result = generator(prompt, max_new_tokens=150)[0]['generated_text']
return result.split("Question:")[-1].strip()
topics = ["Combinatorics", "Logic", "Set Theory", "Functions", "Relations", "Graph Theory"]
difficulties = ["Easy", "Medium", "Hard"]
gr.Interface(
fn=generate_question,
inputs=[gr.Dropdown(choices=topics, label="Select Topic"),
gr.Dropdown(choices=difficulties, label="Select Difficulty")],
outputs="text",
title="Discrete Math Question Generator"
).launch()