MrSimple01 commited on
Commit
3add489
·
verified ·
1 Parent(s): 838730b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +133 -83
app.py CHANGED
@@ -1,83 +1,133 @@
1
- # app.py
2
- import os
3
- import gradio as gr
4
- import tempfile
5
- from video_processing import (
6
- process_video_file,
7
- )
8
- from quiz_processing import process_text
9
-
10
- ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY", None)
11
- GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY', None)
12
-
13
- def combined_process_video_file(video_file, output_format, elevenlabs_api_key, model_id, google_api_key):
14
- audio_path, audio_msg, transcript_file, transcript_msg, transcript_text, _ = process_video_file(
15
- video_file, output_format, elevenlabs_api_key, model_id
16
- )
17
-
18
- if not transcript_text:
19
- return audio_path, audio_msg, transcript_file, transcript_msg, "No transcript text to analyze", None, None
20
-
21
- formatted_quiz, quiz_file, json_file = process_text(transcript_text, google_api_key)
22
-
23
- return audio_path, audio_msg, transcript_file, transcript_msg, formatted_quiz, quiz_file, json_file
24
-
25
- # Create the Gradio interface
26
- with gr.Blocks(title="Video to Quiz Generator") as app:
27
- gr.Markdown("Video => Quiz")
28
- 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.")
29
-
30
- with gr.Row():
31
- with gr.Column():
32
- elevenlabs_api_key = gr.Textbox(
33
- placeholder="Enter your ElevenLabs API key",
34
- label="ElevenLabs API Key (for transcription)",
35
- type="password",
36
- value=ELEVENLABS_API_KEY
37
- )
38
-
39
- model_id = gr.Dropdown(
40
- choices=["scribe_v1"],
41
- value="scribe_v1",
42
- label="Transcription Model"
43
- )
44
-
45
- google_api_key = gr.Textbox(
46
- placeholder="Enter your Google Gemini API key",
47
- label="Google API Key (for quiz generation)",
48
- type="password",
49
- value=GOOGLE_API_KEY
50
- )
51
-
52
- with gr.Tabs():
53
- with gr.TabItem("Upload Video"):
54
- with gr.Row():
55
- with gr.Column():
56
- video_input = gr.Video(label="Upload Video")
57
- format_choice_file = gr.Radio(["mp3", "wav"], value="mp3", label="Audio Format")
58
- extract_button_file = gr.Button("Process Video & Generate Quiz")
59
-
60
- with gr.Column():
61
- audio_output_file = gr.Audio(label="Extracted Audio", type="filepath")
62
- status_output_file = gr.Textbox(label="Audio Extraction Status")
63
- transcript_file_output = gr.File(label="Transcription Text File")
64
- transcript_status_output = gr.Textbox(label="Transcription Status")
65
-
66
- with gr.Row():
67
- with gr.Column():
68
- quiz_output_file = gr.Textbox(
69
- label="Generated Quiz",
70
- lines=15
71
- )
72
- with gr.Row():
73
- quiz_file_output_file = gr.File(label="Download Quiz Text")
74
- json_file_output_file = gr.File(label="Download Quiz JSON")
75
-
76
- extract_button_file.click(
77
- fn=combined_process_video_file,
78
- inputs=[video_input, format_choice_file, elevenlabs_api_key, model_id, google_api_key],
79
- outputs=[audio_output_file, status_output_file, transcript_file_output,
80
- transcript_status_output, quiz_output_file, quiz_file_output_file, json_file_output_file]
81
- )
82
- if __name__ == "__main__":
83
- app.launch(share= True, debug = True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)