Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| gr.Markdown("## π― Smart Learning Assistant") | |
| # Load models (lightweight for Spaces) | |
| qa_pipeline = pipeline("text2text-generation", model="google/flan-t5-small") | |
| summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") | |
| # ---------------- FUNCTIONS ---------------- # | |
| def answer_question(text): | |
| result = qa_pipeline(f"Answer this question: {text}", max_length=100) | |
| return result[0]['generated_text'] | |
| def summarize_text(text): | |
| result = summarizer(text, max_length=80, min_length=20, do_sample=False) | |
| return result[0]['summary_text'] | |
| def generate_quiz(topic): | |
| prompt = f"Generate 3 multiple choice questions with answers on: {topic}" | |
| result = qa_pipeline(prompt, max_length=200) | |
| return result[0]['generated_text'] | |
| # ---------------- UI ---------------- # | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# π AI Study Assistant") | |
| gr.Markdown("### π Ask questions | Summarize notes | Generate quizzes") | |
| with gr.Tabs(): | |
| # πΉ TAB 1: Q&A | |
| with gr.Tab("π¬ Ask Doubt"): | |
| q_input = gr.Textbox(lines=3, placeholder="Enter your question...") | |
| q_output = gr.Textbox(label="Answer") | |
| q_btn = gr.Button("Get Answer") | |
| q_btn.click(answer_question, inputs=q_input, outputs=q_output) | |
| # πΉ TAB 2: Summary | |
| with gr.Tab("π Summarize"): | |
| s_input = gr.Textbox(lines=6, placeholder="Paste your notes here...") | |
| s_output = gr.Textbox(label="Summary") | |
| s_btn = gr.Button("Summarize") | |
| s_btn.click(summarize_text, inputs=s_input, outputs=s_output) | |
| # πΉ TAB 3: Quiz | |
| with gr.Tab("π§ Generate Quiz"): | |
| quiz_input = gr.Textbox(placeholder="Enter topic (e.g., DBMS, AI)") | |
| quiz_output = gr.Textbox(label="Quiz") | |
| quiz_btn = gr.Button("Generate") | |
| quiz_btn.click(generate_quiz, inputs=quiz_input, outputs=quiz_output) | |
| # Launch | |
| if __name__ == "__main__": | |
| demo.launch() |