File size: 10,546 Bytes
5f2eb21
 
 
89909ae
5f2eb21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import os
import gradio as gr
import tempfile
from src.video_processing import extract_audio_from_video, process_video_file, process_audio_document, process_youtube_video
from src.documentProcessing import process_document

ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY", None)
GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY', None)

with gr.Blocks(title="Document & Media Processing Tool") as app:
    gr.Markdown("# Document & Media Processor")
    gr.Markdown("Upload a document, video, audio, or provide a YouTube link to generate summaries and quizzes.")
    
    with gr.Row():
        with gr.Column():
            elevenlabs_api_key = gr.Textbox(
                placeholder="Enter your ElevenLabs API key",
                label="ElevenLabs API Key (for transcription)",
                type="password",
                value=ELEVENLABS_API_KEY
            )
            model_id = gr.Dropdown(
                choices=["scribe_v1"],
                value="scribe_v1",
                label="Transcription Model"
            )
            gemini_api_key = gr.Textbox(
                placeholder="Enter your Google Gemini API key",
                label="Google Gemini API Key",
                type="password",
                value=GOOGLE_API_KEY
            )

    with gr.Row():
        with gr.Column():
            language_selector = gr.Radio(
                choices=["Uzbek", "English", "Russian"],
                value="English",
                label="Content Language"
            )

    with gr.Tabs():
        with gr.TabItem("Upload Document"):
            with gr.Row():
                with gr.Column():
                    document_input = gr.File(label="Upload Document", file_types=[".pdf", ".docx", ".txt"])
                    with gr.Row():
                        generate_summary_button = gr.Button("Generate Summary")
                        generate_quiz_button = gr.Button("Generate Quiz")
                with gr.Column():
                    document_status_output = gr.Textbox(label="Document Processing Status")
                    document_text_file_output = gr.File(label="Extracted Text File")
            with gr.Row():
                with gr.Column():
                    document_output = gr.Textbox(
                        label="Generated Content",
                        lines=15
                    )
                    with gr.Row():
                        document_file_output = gr.File(label="Download Text File")
                        document_json_file_output = gr.File(label="Download JSON File")
        
        # Video Upload Tab
        with gr.TabItem("Upload Video"):
            with gr.Row():
                with gr.Column():
                    video_input = gr.Video(label="Upload Video")
                    format_choice_file = gr.Radio(["mp3", "wav"], value="mp3", label="Audio Format")
                    with gr.Row():
                        video_summary_button = gr.Button("Generate Summary")
                        video_quiz_button = gr.Button("Generate Quiz")
                with gr.Column():
                    audio_output_file = gr.Audio(label="Extracted Audio", type="filepath")
                    status_output_file = gr.Textbox(label="Audio Extraction Status")
                    transcript_file_output = gr.File(label="Transcription Text File")
                    transcript_status_output = gr.Textbox(label="Transcription Status")
            with gr.Row():
                with gr.Column():
                    video_output = gr.Textbox(
                        label="Generated Content",
                        lines=15
                    )
                    with gr.Row():
                        video_text_file_output = gr.File(label="Download Text File")
                        video_json_file_output = gr.File(label="Download JSON File")
        
        # YouTube Tab
        with gr.TabItem("YouTube Video"):
            with gr.Row():
                with gr.Column():
                    youtube_url = gr.Textbox(
                        placeholder="Enter YouTube URL",
                        label="YouTube URL"
                    )
                    yt_format_choice = gr.Radio(["mp3", "wav"], value="mp3", label="Audio Format")
                    with gr.Row():
                        youtube_summary_button = gr.Button("Generate Summary")
                        youtube_quiz_button = gr.Button("Generate Quiz")
                with gr.Column():
                    yt_audio_output = gr.Audio(label="Extracted Audio", type="filepath")
                    yt_status_output = gr.Textbox(label="YouTube Processing Status")
                    yt_transcript_file_output = gr.File(label="Transcription Text File")
                    yt_transcript_status_output = gr.Textbox(label="Transcription Status")
            with gr.Row():
                with gr.Column():
                    youtube_output = gr.Textbox(
                        label="Generated Content",
                        lines=15
                    )
                    with gr.Row():
                        youtube_text_file_output = gr.File(label="Download Text File")
                        youtube_json_file_output = gr.File(label="Download JSON File")
        
        # Audio Tab
        with gr.TabItem("Upload Audio"):
            with gr.Row():
                with gr.Column():
                    audio_input = gr.Audio(label="Upload Audio", type="filepath")
                    with gr.Row():
                        audio_summary_button = gr.Button("Generate Summary")
                        audio_quiz_button = gr.Button("Generate Quiz")
                with gr.Column():
                    audio_status_output = gr.Textbox(label="Audio Processing Status")
                    audio_transcript_file_output = gr.File(label="Transcription Text File")
            with gr.Row():
                with gr.Column():
                    audio_output = gr.Textbox(
                        label="Generated Content",
                        lines=15
                    )
                    with gr.Row():
                        audio_text_file_output = gr.File(label="Download Text File")
                        audio_json_file_output = gr.File(label="Download JSON File")

    # Document processing
    generate_summary_button.click(
        fn=process_document,
        inputs=[
            document_input,
            gemini_api_key,
            language_selector,
            gr.State("summary") 
        ],
        outputs=[
            document_status_output,
            document_text_file_output,
            document_output,
            document_file_output,
            document_json_file_output
        ]
    )
    
    generate_quiz_button.click(
        fn=process_document,
        inputs=[
            document_input,
            gemini_api_key,
            language_selector,
            gr.State("quiz") 
        ],
        outputs=[
            document_status_output,
            document_text_file_output,
            document_output,
            document_file_output,
            document_json_file_output
        ]
    )
    
    # Video processing
    video_summary_button.click(
        fn=process_video_file,
        inputs=[
            video_input, 
            format_choice_file, 
            elevenlabs_api_key, 
            model_id, 
            gemini_api_key,
            language_selector,
            gr.State("summary") 
        ],
        outputs=[
            audio_output_file, 
            status_output_file, 
            transcript_file_output,
            transcript_status_output, 
            video_output, 
            video_text_file_output, 
            video_json_file_output
        ]
    )
    
    video_quiz_button.click(
        fn=process_video_file,
        inputs=[
            video_input, 
            format_choice_file, 
            elevenlabs_api_key, 
            model_id, 
            gemini_api_key,
            language_selector,
            gr.State("quiz")  
        ],
        outputs=[
            audio_output_file, 
            status_output_file, 
            transcript_file_output,
            transcript_status_output, 
            video_output, 
            video_text_file_output, 
            video_json_file_output
        ]
    )
    
    # YouTube processing
    youtube_summary_button.click(
        fn=process_youtube_video,
        inputs=[
            youtube_url,
            yt_format_choice,
            elevenlabs_api_key,
            model_id,
            gemini_api_key,
            language_selector,
            gr.State("summary")  
        ],
        outputs=[
            yt_audio_output,
            yt_status_output,
            yt_transcript_file_output,
            yt_transcript_status_output,
            youtube_output,
            youtube_text_file_output,
            youtube_json_file_output
        ]
    )
    
    youtube_quiz_button.click(
        fn=process_youtube_video,
        inputs=[
            youtube_url,
            yt_format_choice,
            elevenlabs_api_key,
            model_id,
            gemini_api_key,
            language_selector,
            gr.State("quiz")  
        ],
        outputs=[
            yt_audio_output,
            yt_status_output,
            yt_transcript_file_output,
            yt_transcript_status_output,
            youtube_output,
            youtube_text_file_output,
            youtube_json_file_output
        ]
    )
    
    # Audio processing
    audio_summary_button.click(
        fn=process_audio_document,
        inputs=[
            audio_input,
            elevenlabs_api_key,
            model_id,
            gemini_api_key,
            language_selector,
            gr.State("summary") 
        ],
        outputs=[
            audio_status_output,
            audio_transcript_file_output,
            audio_output,
            audio_text_file_output,
            audio_json_file_output
        ]
    )
    
    audio_quiz_button.click(
        fn=process_audio_document,
        inputs=[
            audio_input,
            elevenlabs_api_key,
            model_id,
            gemini_api_key,
            language_selector,
            gr.State("quiz") 
        ],
        outputs=[
            audio_status_output,
            audio_transcript_file_output,
            audio_output,
            audio_text_file_output,
            audio_json_file_output
        ]
    )

if __name__ == "__main__":
    app.launch(share=True, debug=True)