Spaces:
Running
Running
File size: 2,331 Bytes
1f253e4 | 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | import gradio as gr
from transformers import pipeline
# Hugging Face AI model
model = pipeline(
"text2text-generation",
model="google/flan-t5-base"
)
def generate_study_pack(topic):
if not topic or not topic.strip():
return "β οΈ Please enter a topic or study notes."
prompt = f"""
Create a useful study guide for the following topic:
{topic}
Give the answer in exactly these sections:
EASY EXPLANATION:
Explain the topic simply for a student.
SHORT SUMMARY:
Give 4 important points.
EXAM IMPORTANT POINTS:
Give 5 important points.
MCQ QUIZ:
Create 5 multiple choice questions.
Give 4 options for each question and clearly mention the correct answer.
FLASHCARDS:
Create 3 question and answer flashcards.
Use simple English and clear formatting.
"""
try:
result = model(
prompt,
max_new_tokens=500,
do_sample=False
)
return result[0]["generated_text"]
except Exception as e:
return f"β οΈ Error: {str(e)}"
# Custom CSS
css = """
body {
background: #f5f7fb;
}
.title {
text-align: center;
font-size: 38px;
font-weight: bold;
}
.subtitle {
text-align: center;
font-size: 18px;
color: #666;
}
button {
font-size: 18px !important;
}
"""
with gr.Blocks(
title="StudySpark AI",
css=css
) as demo:
gr.HTML("""
<div class="title">π StudySpark AI</div>
<div class="subtitle">
Your AI-powered study companion
</div>
<br>
""")
gr.Markdown(
"### β¨ Enter any topic or paste your study notes"
)
topic = gr.Textbox(
label="π Topic / Study Notes",
placeholder="Example: Data Mining is the process of discovering useful patterns...",
lines=8
)
generate_btn = gr.Button(
"π Generate Study Pack",
variant="primary"
)
output = gr.Textbox(
label="π Your Study Pack",
lines=30,
show_copy_button=True
)
generate_btn.click(
fn=generate_study_pack,
inputs=topic,
outputs=output
)
gr.Markdown("""
### π‘ Try these topics
`Data Mining`
`Photosynthesis`
`Artificial Intelligence`
`Computer Networks`
`Database Management System`
""")
demo.launch() |