Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import google.generativeai as genai
|
3 |
+
|
4 |
+
genai.configure(api_key="AIzaSyBPQF0g5EfEPzEiGRzA3iNzJZK4jDukMvE")
|
5 |
+
|
6 |
+
model = genai.GenerativeModel('gemini-pro')
|
7 |
+
|
8 |
+
def generate_summary_and_quiz(transcript, num_questions):
|
9 |
+
"""Generate a summary and quiz questions based on the video transcript."""
|
10 |
+
prompt = f"""
|
11 |
+
Based on the following video lecture transcript, please provide:
|
12 |
+
1. A concise summary of the main points (about 100 words)
|
13 |
+
2. {num_questions} multiple-choice quiz questions to test understanding of key concepts
|
14 |
+
|
15 |
+
Transcript:
|
16 |
+
{transcript}
|
17 |
+
|
18 |
+
Format your response as follows:
|
19 |
+
Summary:
|
20 |
+
[Your summary here]
|
21 |
+
|
22 |
+
Quiz Questions:
|
23 |
+
1. [Question]
|
24 |
+
a) [Option A]
|
25 |
+
b) [Option B]
|
26 |
+
c) [Option C]
|
27 |
+
d) [Option D]
|
28 |
+
Correct Answer: [Correct option letter]
|
29 |
+
|
30 |
+
2. [Next question and options...]
|
31 |
+
|
32 |
+
Ensure the questions cover different aspects of the lecture and vary in difficulty.
|
33 |
+
"""
|
34 |
+
|
35 |
+
try:
|
36 |
+
response = model.generate_content(prompt)
|
37 |
+
return response.text
|
38 |
+
except Exception as e:
|
39 |
+
return f"Error generating summary and quiz: {str(e)}"
|
40 |
+
|
41 |
+
def process_lecture(transcript, num_questions):
|
42 |
+
with gr.Row():
|
43 |
+
gr.Markdown("Generating summary and quiz...")
|
44 |
+
result = generate_summary_and_quiz(transcript, num_questions)
|
45 |
+
return result
|
46 |
+
|
47 |
+
with gr.Blocks() as demo:
|
48 |
+
gr.Markdown("# Video Lecture Summarizer and Quiz Generator")
|
49 |
+
|
50 |
+
transcript_input = gr.Textbox(label="Video Lecture Transcript", lines=10, placeholder="Paste the video transcript or a detailed description of the lecture content here...")
|
51 |
+
num_questions = gr.Slider(minimum=1, maximum=10, value=3, step=1, label="Number of Quiz Questions")
|
52 |
+
|
53 |
+
generate_btn = gr.Button("Generate Summary and Quiz")
|
54 |
+
output = gr.Textbox(label="Summary and Quiz", lines=20)
|
55 |
+
|
56 |
+
generate_btn.click(process_lecture, inputs=[transcript_input, num_questions], outputs=output)
|
57 |
+
|
58 |
+
if __name__ == "__main__":
|
59 |
+
demo.launch()
|