region:us
---
{}
---
import gradio as gr
from transformers import pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
question_generator = pipeline("text2text-generation", model="valhalla/t5-base-qa-qg-hl")
def summarize_text(text):
    summary = summarizer(text, max_length=500, min_length=50, do_sample=False)
    return summary[0]['summary_text']
def generate_questions(text):
    prompt = f"Generate 5 questions based on the following text. The questions should be difficult and require knowlage of the topic. Text: {text}"
    questions = question_generator(f"generate questions: {text}") 
    return questions[0]['generated_text']
def create_app():
    theme = gr.themes.Ocean()  
    with gr.Blocks(theme=theme) as demo:
        gr.Markdown("Study Buddy")
        with gr.Tab("Summary"):
            text_input = gr.TextArea(label="Enter Lecture Notes or Text", placeholder="Paste your text here...", lines=8)
            summary_output = gr.Textbox(label="Summary", placeholder="Summary will appear here...", interactive=False)
            summarize_btn = gr.Button("Summarize")
            summarize_btn.click(summarize_text, inputs=text_input, outputs=summary_output)
        with gr.Tab("Study Questions"):
            context_input = gr.TextArea(label="Enter Context (e.g., textbook chapter, notes)", placeholder="Paste your context here...", lines=8)
            question_output = gr.Textbox(label="Generated Questions", placeholder="Generated questions will appear here...", interactive=False)
            generate_btn = gr.Button("Generate Questions")
            generate_btn.click(generate_questions, inputs=context_input, outputs=question_output)
    return demo

app = create_app()
app.launch(share=True)