MrSimple01 commited on
Commit
2bd5429
·
verified ·
1 Parent(s): 38dad4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +171 -72
app.py CHANGED
@@ -1,52 +1,15 @@
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_1 import analyze_document
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 = analyze_document(
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():
@@ -61,13 +24,18 @@ with gr.Blocks(title="Video to Quiz Generator") as app:
61
  value="scribe_v1",
62
  label="Transcription Model"
63
  )
64
- google_api_key = gr.Textbox(
65
- placeholder="Enter your Google Gemini or Claude or OpenAI API key",
66
- label="Google API Key (for quiz generation)",
67
  type="password",
 
68
  )
69
-
70
- # Add the new course information textboxes
 
 
 
 
71
  with gr.Row():
72
  with gr.Column():
73
  course_name = gr.Textbox(
@@ -82,7 +50,15 @@ with gr.Blocks(title="Video to Quiz Generator") as app:
82
  placeholder="Enter the lesson name",
83
  label="Lesson Name"
84
  )
85
-
 
 
 
 
 
 
 
 
86
  with gr.Tabs():
87
  with gr.TabItem("Upload Video"):
88
  with gr.Row():
@@ -104,29 +80,152 @@ with gr.Blocks(title="Video to Quiz Generator") as app:
104
  with gr.Row():
105
  quiz_file_output_file = gr.File(label="Download Quiz Text")
106
  json_file_output_file = gr.File(label="Download Quiz JSON")
107
-
108
- extract_button_file.click(
109
- fn=combined_process_video_file,
110
- inputs=[
111
- video_input,
112
- format_choice_file,
113
- elevenlabs_api_key,
114
- model_id,
115
- google_api_key,
116
- course_name,
117
- section_name,
118
- lesson_name
119
- ],
120
- outputs=[
121
- audio_output_file,
122
- status_output_file,
123
- transcript_file_output,
124
- transcript_status_output,
125
- quiz_output_file,
126
- quiz_file_output_file,
127
- json_file_output_file
128
- ]
129
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  if __name__ == "__main__":
132
  app.launch(share=True, debug=True)
 
1
  import os
2
  import gradio as gr
3
  import tempfile
4
+ from src.mainFunctions import *
5
+
 
 
6
  ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY", None)
7
  GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY', None)
8
+ CLAUDE_API_KEY = os.environ.get('CLAUDE_API_KEY', None)
9
 
10
+ with gr.Blocks(title="Document to Quiz Generator") as app:
11
+ gr.Markdown("# Document & Media => Quiz")
12
+ gr.Markdown("Upload a video, audio, PDF, or Word document to automatically generate a quiz with topics, key concepts, summaries, and questions.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  with gr.Row():
15
  with gr.Column():
 
24
  value="scribe_v1",
25
  label="Transcription Model"
26
  )
27
+ gemini_api_key = gr.Textbox(
28
+ placeholder="Enter your Google Gemini API key",
29
+ label="Google Gemini API Key",
30
  type="password",
31
+ value=GOOGLE_API_KEY
32
  )
33
+ claude_api_key = gr.Textbox(
34
+ placeholder="Enter your Claude API key",
35
+ label="Claude API Key",
36
+ type="password"
37
+ )
38
+
39
  with gr.Row():
40
  with gr.Column():
41
  course_name = gr.Textbox(
 
50
  placeholder="Enter the lesson name",
51
  label="Lesson Name"
52
  )
53
+
54
+ with gr.Row():
55
+ with gr.Column():
56
+ language_selector = gr.Radio(
57
+ choices=["Uzbek", "English", "Russian"],
58
+ value="English",
59
+ label="Content Language"
60
+ )
61
+
62
  with gr.Tabs():
63
  with gr.TabItem("Upload Video"):
64
  with gr.Row():
 
80
  with gr.Row():
81
  quiz_file_output_file = gr.File(label="Download Quiz Text")
82
  json_file_output_file = gr.File(label="Download Quiz JSON")
83
+
84
+ # PDF Tab
85
+ with gr.TabItem("Upload PDF"):
86
+ with gr.Row():
87
+ with gr.Column():
88
+ pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"])
89
+ process_pdf_button = gr.Button("Process PDF & Generate Quiz")
90
+ with gr.Column():
91
+ pdf_status_output = gr.Textbox(label="PDF Processing Status")
92
+ pdf_text_file_output = gr.File(label="Extracted Text File")
93
+ with gr.Row():
94
+ with gr.Column():
95
+ pdf_quiz_output = gr.Textbox(
96
+ label="Generated Quiz",
97
+ lines=15
98
+ )
99
+ with gr.Row():
100
+ pdf_quiz_file_output = gr.File(label="Download Quiz Text")
101
+ pdf_json_file_output = gr.File(label="Download Quiz JSON")
102
+
103
+ # Word Document Tab
104
+ with gr.TabItem("Upload Word Document"):
105
+ with gr.Row():
106
+ with gr.Column():
107
+ docx_input = gr.File(label="Upload Word Document", file_types=[".docx"])
108
+ process_docx_button = gr.Button("Process Word Document & Generate Quiz")
109
+ with gr.Column():
110
+ docx_status_output = gr.Textbox(label="Word Document Processing Status")
111
+ docx_text_file_output = gr.File(label="Extracted Text File")
112
+ with gr.Row():
113
+ with gr.Column():
114
+ docx_quiz_output = gr.Textbox(
115
+ label="Generated Quiz",
116
+ lines=15
117
+ )
118
+ with gr.Row():
119
+ docx_quiz_file_output = gr.File(label="Download Quiz Text")
120
+ docx_json_file_output = gr.File(label="Download Quiz JSON")
121
+
122
+ # Audio Tab
123
+ with gr.TabItem("Upload Audio"):
124
+ with gr.Row():
125
+ with gr.Column():
126
+ audio_input = gr.Audio(label="Upload Audio", type="filepath")
127
+ process_audio_button = gr.Button("Process Audio & Generate Quiz")
128
+ with gr.Column():
129
+ audio_status_output = gr.Textbox(label="Audio Processing Status")
130
+ audio_transcript_file_output = gr.File(label="Transcription Text File")
131
+ with gr.Row():
132
+ with gr.Column():
133
+ audio_quiz_output = gr.Textbox(
134
+ label="Generated Quiz",
135
+ lines=15
136
+ )
137
+ with gr.Row():
138
+ audio_quiz_file_output = gr.File(label="Download Quiz Text")
139
+ audio_json_file_output = gr.File(label="Download Quiz JSON")
140
+
141
+ # Connect video processing
142
+ extract_button_file.click(
143
+ fn=combined_process_video_file,
144
+ inputs=[
145
+ video_input,
146
+ format_choice_file,
147
+ elevenlabs_api_key,
148
+ model_id,
149
+ gemini_api_key,
150
+ claude_api_key,
151
+ course_name,
152
+ section_name,
153
+ lesson_name,
154
+ language_selector
155
+ ],
156
+ outputs=[
157
+ audio_output_file,
158
+ status_output_file,
159
+ transcript_file_output,
160
+ transcript_status_output,
161
+ quiz_output_file,
162
+ quiz_file_output_file,
163
+ json_file_output_file
164
+ ]
165
+ )
166
+
167
+ # Connect PDF processing
168
+ process_pdf_button.click(
169
+ fn=process_pdf_document,
170
+ inputs=[
171
+ pdf_input,
172
+ gemini_api_key,
173
+ claude_api_key,
174
+ course_name,
175
+ section_name,
176
+ lesson_name,
177
+ language_selector
178
+ ],
179
+ outputs=[
180
+ pdf_status_output,
181
+ pdf_text_file_output,
182
+ pdf_quiz_output,
183
+ pdf_quiz_file_output,
184
+ pdf_json_file_output
185
+ ]
186
+ )
187
+
188
+ process_docx_button.click(
189
+ fn=process_docx_document,
190
+ inputs=[
191
+ docx_input,
192
+ gemini_api_key,
193
+ claude_api_key,
194
+ course_name,
195
+ section_name,
196
+ lesson_name,
197
+ language_selector
198
+ ],
199
+ outputs=[
200
+ docx_status_output,
201
+ docx_text_file_output,
202
+ docx_quiz_output,
203
+ docx_quiz_file_output,
204
+ docx_json_file_output
205
+ ]
206
+ )
207
+
208
+ process_audio_button.click(
209
+ fn=process_audio_document,
210
+ inputs=[
211
+ audio_input,
212
+ elevenlabs_api_key,
213
+ model_id,
214
+ gemini_api_key,
215
+ claude_api_key,
216
+ course_name,
217
+ section_name,
218
+ lesson_name,
219
+ language_selector
220
+ ],
221
+ outputs=[
222
+ audio_status_output,
223
+ audio_transcript_file_output,
224
+ audio_quiz_output,
225
+ audio_quiz_file_output,
226
+ audio_json_file_output
227
+ ]
228
+ )
229
 
230
  if __name__ == "__main__":
231
  app.launch(share=True, debug=True)