import os import gradio as gr import tempfile from video_processing import ( process_video_file, ) from quiz_processing import analyze_document ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY", None) GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY', None) def combined_process_video_file(video_file, output_format, elevenlabs_api_key, model_id, gemini_api_key, claude_api_key, course_name, section_name, lesson_name, language): result = process_video_file( video_file, output_format, elevenlabs_api_key, model_id ) audio_path = result[0] audio_msg = result[1] transcript_file = result[2] transcript_msg = result[3] transcript_text = result[4] if not transcript_text: return audio_path, audio_msg, transcript_file, transcript_msg, "No transcript text to analyze", None, None enriched_transcript = f""" COURSE: {course_name} SECTION: {section_name} LESSON: {lesson_name} TRANSCRIPT: {transcript_text} """ formatted_quiz, quiz_file, json_file = analyze_document( enriched_transcript, gemini_api_key, claude_api_key, course_name, section_name, lesson_name, language ) return audio_path, audio_msg, transcript_file, transcript_msg, formatted_quiz, quiz_file, json_file with gr.Blocks(title="Video to Quiz Generator") as app: gr.Markdown("# Video => Quiz") 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.") 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 ) claude_api_key = gr.Textbox( placeholder="Enter your Claude API key", label="Claude API Key", type="password" ) with gr.Row(): with gr.Column(): course_name = gr.Textbox( placeholder="Enter the course name", label="Course Name" ) section_name = gr.Textbox( placeholder="Enter the section name", label="Section Name" ) lesson_name = gr.Textbox( placeholder="Enter the lesson name", label="Lesson Name" ) 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 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") extract_button_file = gr.Button("Process Video & 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(): quiz_output_file = gr.Textbox( label="Generated Quiz", lines=15 ) with gr.Row(): quiz_file_output_file = gr.File(label="Download Quiz Text") json_file_output_file = gr.File(label="Download Quiz JSON") extract_button_file.click( fn=combined_process_video_file, inputs=[ video_input, format_choice_file, elevenlabs_api_key, model_id, gemini_api_key, claude_api_key, course_name, section_name, lesson_name, language_selector ], outputs=[ audio_output_file, status_output_file, transcript_file_output, transcript_status_output, quiz_output_file, quiz_file_output_file, json_file_output_file ] ) if __name__ == "__main__": app.launch(share=True, debug=True)