Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
import tempfile | |
from src.video_processing import process_video_file | |
from src.documentProcessing import process_pdf_file, process_docx_file | |
from src.audioProcessing import process_audio_file | |
from src.quiz_processing import analyze_document | |
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 | |
def process_pdf_document(pdf_file, gemini_api_key, claude_api_key, course_name, | |
section_name, lesson_name, language): | |
if not pdf_file: | |
return "No file uploaded", None, None, None | |
text_file, text_content = process_pdf_file(pdf_file) | |
if not text_content or text_file is None: | |
return f"Error: {text_content}", None, None, None | |
extraction_msg = f"Text extracted from PDF successfully. Length: {len(text_content)} characters." | |
enriched_content = f""" | |
COURSE: {course_name} | |
SECTION: {section_name} | |
LESSON: {lesson_name} | |
CONTENT: | |
{text_content} | |
""" | |
formatted_quiz, quiz_file, json_file = analyze_document( | |
enriched_content, | |
gemini_api_key, | |
claude_api_key, | |
course_name, | |
section_name, | |
lesson_name, | |
language | |
) | |
return extraction_msg, text_file, formatted_quiz, quiz_file, json_file | |
def process_docx_document(docx_file, gemini_api_key, claude_api_key, course_name, | |
section_name, lesson_name, language): | |
if not docx_file: | |
return "No file uploaded", None, None, None | |
text_file, text_content = process_docx_file(docx_file) | |
if not text_content or text_file is None: | |
return f"Error: {text_content}", None, None, None | |
extraction_msg = f"Text extracted from Word document successfully. Length: {len(text_content)} characters." | |
enriched_content = f""" | |
COURSE: {course_name} | |
SECTION: {section_name} | |
LESSON: {lesson_name} | |
CONTENT: | |
{text_content} | |
""" | |
formatted_quiz, quiz_file, json_file = analyze_document( | |
enriched_content, | |
gemini_api_key, | |
claude_api_key, | |
course_name, | |
section_name, | |
lesson_name, | |
language | |
) | |
return extraction_msg, text_file, formatted_quiz, quiz_file, json_file | |
def process_audio_document(audio_file, elevenlabs_api_key, model_id, gemini_api_key, | |
claude_api_key, course_name, section_name, lesson_name, language): | |
if not audio_file: | |
return "No file uploaded", None, None, None, None | |
transcript_file, transcript_msg, transcript_text = process_audio_file( | |
audio_file, elevenlabs_api_key, model_id | |
) | |
if not transcript_text or transcript_file is None: | |
return transcript_msg, None, None, None, None | |
enriched_content = f""" | |
COURSE: {course_name} | |
SECTION: {section_name} | |
LESSON: {lesson_name} | |
TRANSCRIPT: | |
{transcript_text} | |
""" | |
formatted_quiz, quiz_file, json_file = analyze_document( | |
enriched_content, | |
gemini_api_key, | |
claude_api_key, | |
course_name, | |
section_name, | |
lesson_name, | |
language | |
) | |
return transcript_msg, transcript_file, formatted_quiz, quiz_file, json_file | |