Spaces:
Runtime error
Runtime error
File size: 1,304 Bytes
e9b7c7d f4b4b3e ee303fb e9b7c7d e9ec0e9 e9b7c7d ee303fb e9b7c7d 1a2993b e9b7c7d f4b4b3e e9b7c7d ee303fb f4b4b3e e9b7c7d |
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 30 31 32 33 34 35 36 37 38 39 40 |
!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() |