Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,83 +1,133 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
import
|
4 |
-
import
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import tempfile
|
4 |
+
from video_processing import (
|
5 |
+
process_video_file,
|
6 |
+
)
|
7 |
+
from quiz_processing import process_text
|
8 |
+
ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY", None)
|
9 |
+
GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY', None)
|
10 |
+
|
11 |
+
def combined_process_video_file(video_file, output_format, elevenlabs_api_key, model_id, google_api_key,
|
12 |
+
course_name, section_name, lesson_name):
|
13 |
+
result = process_video_file(
|
14 |
+
video_file, output_format, elevenlabs_api_key, model_id
|
15 |
+
)
|
16 |
+
|
17 |
+
audio_path = result[0]
|
18 |
+
audio_msg = result[1]
|
19 |
+
transcript_file = result[2]
|
20 |
+
transcript_msg = result[3]
|
21 |
+
transcript_text = result[4]
|
22 |
+
|
23 |
+
if not transcript_text:
|
24 |
+
return audio_path, audio_msg, transcript_file, transcript_msg, "No transcript text to analyze", None, None
|
25 |
+
|
26 |
+
enriched_transcript = f"""
|
27 |
+
COURSE: {course_name}
|
28 |
+
SECTION: {section_name}
|
29 |
+
LESSON: {lesson_name}
|
30 |
+
|
31 |
+
TRANSCRIPT:
|
32 |
+
{transcript_text}
|
33 |
+
"""
|
34 |
+
|
35 |
+
# Call process_text with the course information parameters
|
36 |
+
formatted_quiz, quiz_file, json_file = process_text(
|
37 |
+
enriched_transcript,
|
38 |
+
google_api_key,
|
39 |
+
course_name,
|
40 |
+
section_name,
|
41 |
+
lesson_name
|
42 |
+
)
|
43 |
+
|
44 |
+
return audio_path, audio_msg, transcript_file, transcript_msg, formatted_quiz, quiz_file, json_file
|
45 |
+
|
46 |
+
|
47 |
+
with gr.Blocks(title="Video to Quiz Generator") as app:
|
48 |
+
gr.Markdown("Video => Quiz")
|
49 |
+
gr.Markdown("Upload a video or provide a URL to extract audio, transcribe, and automatically generate a quiz with topics, key concepts, summaries, and questions.")
|
50 |
+
|
51 |
+
with gr.Row():
|
52 |
+
with gr.Column():
|
53 |
+
elevenlabs_api_key = gr.Textbox(
|
54 |
+
placeholder="Enter your ElevenLabs API key",
|
55 |
+
label="ElevenLabs API Key (for transcription)",
|
56 |
+
type="password",
|
57 |
+
value=ELEVENLABS_API_KEY
|
58 |
+
)
|
59 |
+
model_id = gr.Dropdown(
|
60 |
+
choices=["scribe_v1"],
|
61 |
+
value="scribe_v1",
|
62 |
+
label="Transcription Model"
|
63 |
+
)
|
64 |
+
google_api_key = gr.Textbox(
|
65 |
+
placeholder="Enter your Google Gemini API key",
|
66 |
+
label="Google API Key (for quiz generation)",
|
67 |
+
type="password",
|
68 |
+
value=GOOGLE_API_KEY
|
69 |
+
)
|
70 |
+
|
71 |
+
# Add the new course information textboxes
|
72 |
+
with gr.Row():
|
73 |
+
with gr.Column():
|
74 |
+
course_name = gr.Textbox(
|
75 |
+
placeholder="Enter the course name",
|
76 |
+
label="Course Name"
|
77 |
+
)
|
78 |
+
section_name = gr.Textbox(
|
79 |
+
placeholder="Enter the section name",
|
80 |
+
label="Section Name"
|
81 |
+
)
|
82 |
+
lesson_name = gr.Textbox(
|
83 |
+
placeholder="Enter the lesson name",
|
84 |
+
label="Lesson Name"
|
85 |
+
)
|
86 |
+
|
87 |
+
with gr.Tabs():
|
88 |
+
with gr.TabItem("Upload Video"):
|
89 |
+
with gr.Row():
|
90 |
+
with gr.Column():
|
91 |
+
video_input = gr.Video(label="Upload Video")
|
92 |
+
format_choice_file = gr.Radio(["mp3", "wav"], value="mp3", label="Audio Format")
|
93 |
+
extract_button_file = gr.Button("Process Video & Generate Quiz")
|
94 |
+
with gr.Column():
|
95 |
+
audio_output_file = gr.Audio(label="Extracted Audio", type="filepath")
|
96 |
+
status_output_file = gr.Textbox(label="Audio Extraction Status")
|
97 |
+
transcript_file_output = gr.File(label="Transcription Text File")
|
98 |
+
transcript_status_output = gr.Textbox(label="Transcription Status")
|
99 |
+
with gr.Row():
|
100 |
+
with gr.Column():
|
101 |
+
quiz_output_file = gr.Textbox(
|
102 |
+
label="Generated Quiz",
|
103 |
+
lines=15
|
104 |
+
)
|
105 |
+
with gr.Row():
|
106 |
+
quiz_file_output_file = gr.File(label="Download Quiz Text")
|
107 |
+
json_file_output_file = gr.File(label="Download Quiz JSON")
|
108 |
+
|
109 |
+
extract_button_file.click(
|
110 |
+
fn=combined_process_video_file,
|
111 |
+
inputs=[
|
112 |
+
video_input,
|
113 |
+
format_choice_file,
|
114 |
+
elevenlabs_api_key,
|
115 |
+
model_id,
|
116 |
+
google_api_key,
|
117 |
+
course_name,
|
118 |
+
section_name,
|
119 |
+
lesson_name
|
120 |
+
],
|
121 |
+
outputs=[
|
122 |
+
audio_output_file,
|
123 |
+
status_output_file,
|
124 |
+
transcript_file_output,
|
125 |
+
transcript_status_output,
|
126 |
+
quiz_output_file,
|
127 |
+
quiz_file_output_file,
|
128 |
+
json_file_output_file
|
129 |
+
]
|
130 |
+
)
|
131 |
+
|
132 |
+
if __name__ == "__main__":
|
133 |
+
app.launch(share=True, debug=True)
|