StudySpark-AI / index.html
Jayaviji's picture
Update index.html
1f253e4 verified
Raw History Blame Contribute Delete
2.33 kB
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()