Spaces:
Sleeping
Sleeping
Update src/mainFunctions.py
Browse files- src/mainFunctions.py +143 -143
src/mainFunctions.py
CHANGED
@@ -1,143 +1,143 @@
|
|
1 |
-
import os
|
2 |
-
import gradio as gr
|
3 |
-
import tempfile
|
4 |
-
from video_processing import process_video_file
|
5 |
-
from documentProcessing import process_pdf_file, process_docx_file
|
6 |
-
from audioProcessing import process_audio_file
|
7 |
-
from quiz_processing import analyze_document
|
8 |
-
|
9 |
-
def combined_process_video_file(video_file, output_format, elevenlabs_api_key, model_id,
|
10 |
-
gemini_api_key, claude_api_key, course_name, section_name,
|
11 |
-
lesson_name, language):
|
12 |
-
result = process_video_file(
|
13 |
-
video_file, output_format, elevenlabs_api_key, model_id
|
14 |
-
)
|
15 |
-
|
16 |
-
audio_path = result[0]
|
17 |
-
audio_msg = result[1]
|
18 |
-
transcript_file = result[2]
|
19 |
-
transcript_msg = result[3]
|
20 |
-
transcript_text = result[4]
|
21 |
-
|
22 |
-
if not transcript_text:
|
23 |
-
return audio_path, audio_msg, transcript_file, transcript_msg, "No transcript text to analyze", None, None
|
24 |
-
|
25 |
-
enriched_transcript = f"""
|
26 |
-
COURSE: {course_name}
|
27 |
-
SECTION: {section_name}
|
28 |
-
LESSON: {lesson_name}
|
29 |
-
|
30 |
-
TRANSCRIPT:
|
31 |
-
{transcript_text}
|
32 |
-
"""
|
33 |
-
|
34 |
-
formatted_quiz, quiz_file, json_file = analyze_document(
|
35 |
-
enriched_transcript,
|
36 |
-
gemini_api_key,
|
37 |
-
claude_api_key,
|
38 |
-
course_name,
|
39 |
-
section_name,
|
40 |
-
lesson_name,
|
41 |
-
language
|
42 |
-
)
|
43 |
-
|
44 |
-
return audio_path, audio_msg, transcript_file, transcript_msg, formatted_quiz, quiz_file, json_file
|
45 |
-
|
46 |
-
def process_pdf_document(pdf_file, gemini_api_key, claude_api_key, course_name,
|
47 |
-
section_name, lesson_name, language):
|
48 |
-
if not pdf_file:
|
49 |
-
return "No file uploaded", None, None, None
|
50 |
-
|
51 |
-
text_file, text_content = process_pdf_file(pdf_file)
|
52 |
-
|
53 |
-
if not text_content or text_file is None:
|
54 |
-
return f"Error: {text_content}", None, None, None
|
55 |
-
|
56 |
-
extraction_msg = f"Text extracted from PDF successfully. Length: {len(text_content)} characters."
|
57 |
-
|
58 |
-
enriched_content = f"""
|
59 |
-
COURSE: {course_name}
|
60 |
-
SECTION: {section_name}
|
61 |
-
LESSON: {lesson_name}
|
62 |
-
|
63 |
-
CONTENT:
|
64 |
-
{text_content}
|
65 |
-
"""
|
66 |
-
|
67 |
-
formatted_quiz, quiz_file, json_file = analyze_document(
|
68 |
-
enriched_content,
|
69 |
-
gemini_api_key,
|
70 |
-
claude_api_key,
|
71 |
-
course_name,
|
72 |
-
section_name,
|
73 |
-
lesson_name,
|
74 |
-
language
|
75 |
-
)
|
76 |
-
|
77 |
-
return extraction_msg, text_file, formatted_quiz, quiz_file, json_file
|
78 |
-
|
79 |
-
def process_docx_document(docx_file, gemini_api_key, claude_api_key, course_name,
|
80 |
-
section_name, lesson_name, language):
|
81 |
-
if not docx_file:
|
82 |
-
return "No file uploaded", None, None, None
|
83 |
-
|
84 |
-
text_file, text_content = process_docx_file(docx_file)
|
85 |
-
|
86 |
-
if not text_content or text_file is None:
|
87 |
-
return f"Error: {text_content}", None, None, None
|
88 |
-
|
89 |
-
extraction_msg = f"Text extracted from Word document successfully. Length: {len(text_content)} characters."
|
90 |
-
|
91 |
-
enriched_content = f"""
|
92 |
-
COURSE: {course_name}
|
93 |
-
SECTION: {section_name}
|
94 |
-
LESSON: {lesson_name}
|
95 |
-
|
96 |
-
CONTENT:
|
97 |
-
{text_content}
|
98 |
-
"""
|
99 |
-
|
100 |
-
formatted_quiz, quiz_file, json_file = analyze_document(
|
101 |
-
enriched_content,
|
102 |
-
gemini_api_key,
|
103 |
-
claude_api_key,
|
104 |
-
course_name,
|
105 |
-
section_name,
|
106 |
-
lesson_name,
|
107 |
-
language
|
108 |
-
)
|
109 |
-
|
110 |
-
return extraction_msg, text_file, formatted_quiz, quiz_file, json_file
|
111 |
-
|
112 |
-
def process_audio_document(audio_file, elevenlabs_api_key, model_id, gemini_api_key,
|
113 |
-
claude_api_key, course_name, section_name, lesson_name, language):
|
114 |
-
if not audio_file:
|
115 |
-
return "No file uploaded", None, None, None, None
|
116 |
-
|
117 |
-
transcript_file, transcript_msg, transcript_text = process_audio_file(
|
118 |
-
audio_file, elevenlabs_api_key, model_id
|
119 |
-
)
|
120 |
-
|
121 |
-
if not transcript_text or transcript_file is None:
|
122 |
-
return transcript_msg, None, None, None, None
|
123 |
-
|
124 |
-
enriched_content = f"""
|
125 |
-
COURSE: {course_name}
|
126 |
-
SECTION: {section_name}
|
127 |
-
LESSON: {lesson_name}
|
128 |
-
|
129 |
-
TRANSCRIPT:
|
130 |
-
{transcript_text}
|
131 |
-
"""
|
132 |
-
|
133 |
-
formatted_quiz, quiz_file, json_file = analyze_document(
|
134 |
-
enriched_content,
|
135 |
-
gemini_api_key,
|
136 |
-
claude_api_key,
|
137 |
-
course_name,
|
138 |
-
section_name,
|
139 |
-
lesson_name,
|
140 |
-
language
|
141 |
-
)
|
142 |
-
|
143 |
-
return transcript_msg, transcript_file, formatted_quiz, quiz_file, json_file
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import tempfile
|
4 |
+
from src.video_processing import process_video_file
|
5 |
+
from documentProcessing import process_pdf_file, process_docx_file
|
6 |
+
from audioProcessing import process_audio_file
|
7 |
+
from quiz_processing import analyze_document
|
8 |
+
|
9 |
+
def combined_process_video_file(video_file, output_format, elevenlabs_api_key, model_id,
|
10 |
+
gemini_api_key, claude_api_key, course_name, section_name,
|
11 |
+
lesson_name, language):
|
12 |
+
result = process_video_file(
|
13 |
+
video_file, output_format, elevenlabs_api_key, model_id
|
14 |
+
)
|
15 |
+
|
16 |
+
audio_path = result[0]
|
17 |
+
audio_msg = result[1]
|
18 |
+
transcript_file = result[2]
|
19 |
+
transcript_msg = result[3]
|
20 |
+
transcript_text = result[4]
|
21 |
+
|
22 |
+
if not transcript_text:
|
23 |
+
return audio_path, audio_msg, transcript_file, transcript_msg, "No transcript text to analyze", None, None
|
24 |
+
|
25 |
+
enriched_transcript = f"""
|
26 |
+
COURSE: {course_name}
|
27 |
+
SECTION: {section_name}
|
28 |
+
LESSON: {lesson_name}
|
29 |
+
|
30 |
+
TRANSCRIPT:
|
31 |
+
{transcript_text}
|
32 |
+
"""
|
33 |
+
|
34 |
+
formatted_quiz, quiz_file, json_file = analyze_document(
|
35 |
+
enriched_transcript,
|
36 |
+
gemini_api_key,
|
37 |
+
claude_api_key,
|
38 |
+
course_name,
|
39 |
+
section_name,
|
40 |
+
lesson_name,
|
41 |
+
language
|
42 |
+
)
|
43 |
+
|
44 |
+
return audio_path, audio_msg, transcript_file, transcript_msg, formatted_quiz, quiz_file, json_file
|
45 |
+
|
46 |
+
def process_pdf_document(pdf_file, gemini_api_key, claude_api_key, course_name,
|
47 |
+
section_name, lesson_name, language):
|
48 |
+
if not pdf_file:
|
49 |
+
return "No file uploaded", None, None, None
|
50 |
+
|
51 |
+
text_file, text_content = process_pdf_file(pdf_file)
|
52 |
+
|
53 |
+
if not text_content or text_file is None:
|
54 |
+
return f"Error: {text_content}", None, None, None
|
55 |
+
|
56 |
+
extraction_msg = f"Text extracted from PDF successfully. Length: {len(text_content)} characters."
|
57 |
+
|
58 |
+
enriched_content = f"""
|
59 |
+
COURSE: {course_name}
|
60 |
+
SECTION: {section_name}
|
61 |
+
LESSON: {lesson_name}
|
62 |
+
|
63 |
+
CONTENT:
|
64 |
+
{text_content}
|
65 |
+
"""
|
66 |
+
|
67 |
+
formatted_quiz, quiz_file, json_file = analyze_document(
|
68 |
+
enriched_content,
|
69 |
+
gemini_api_key,
|
70 |
+
claude_api_key,
|
71 |
+
course_name,
|
72 |
+
section_name,
|
73 |
+
lesson_name,
|
74 |
+
language
|
75 |
+
)
|
76 |
+
|
77 |
+
return extraction_msg, text_file, formatted_quiz, quiz_file, json_file
|
78 |
+
|
79 |
+
def process_docx_document(docx_file, gemini_api_key, claude_api_key, course_name,
|
80 |
+
section_name, lesson_name, language):
|
81 |
+
if not docx_file:
|
82 |
+
return "No file uploaded", None, None, None
|
83 |
+
|
84 |
+
text_file, text_content = process_docx_file(docx_file)
|
85 |
+
|
86 |
+
if not text_content or text_file is None:
|
87 |
+
return f"Error: {text_content}", None, None, None
|
88 |
+
|
89 |
+
extraction_msg = f"Text extracted from Word document successfully. Length: {len(text_content)} characters."
|
90 |
+
|
91 |
+
enriched_content = f"""
|
92 |
+
COURSE: {course_name}
|
93 |
+
SECTION: {section_name}
|
94 |
+
LESSON: {lesson_name}
|
95 |
+
|
96 |
+
CONTENT:
|
97 |
+
{text_content}
|
98 |
+
"""
|
99 |
+
|
100 |
+
formatted_quiz, quiz_file, json_file = analyze_document(
|
101 |
+
enriched_content,
|
102 |
+
gemini_api_key,
|
103 |
+
claude_api_key,
|
104 |
+
course_name,
|
105 |
+
section_name,
|
106 |
+
lesson_name,
|
107 |
+
language
|
108 |
+
)
|
109 |
+
|
110 |
+
return extraction_msg, text_file, formatted_quiz, quiz_file, json_file
|
111 |
+
|
112 |
+
def process_audio_document(audio_file, elevenlabs_api_key, model_id, gemini_api_key,
|
113 |
+
claude_api_key, course_name, section_name, lesson_name, language):
|
114 |
+
if not audio_file:
|
115 |
+
return "No file uploaded", None, None, None, None
|
116 |
+
|
117 |
+
transcript_file, transcript_msg, transcript_text = process_audio_file(
|
118 |
+
audio_file, elevenlabs_api_key, model_id
|
119 |
+
)
|
120 |
+
|
121 |
+
if not transcript_text or transcript_file is None:
|
122 |
+
return transcript_msg, None, None, None, None
|
123 |
+
|
124 |
+
enriched_content = f"""
|
125 |
+
COURSE: {course_name}
|
126 |
+
SECTION: {section_name}
|
127 |
+
LESSON: {lesson_name}
|
128 |
+
|
129 |
+
TRANSCRIPT:
|
130 |
+
{transcript_text}
|
131 |
+
"""
|
132 |
+
|
133 |
+
formatted_quiz, quiz_file, json_file = analyze_document(
|
134 |
+
enriched_content,
|
135 |
+
gemini_api_key,
|
136 |
+
claude_api_key,
|
137 |
+
course_name,
|
138 |
+
section_name,
|
139 |
+
lesson_name,
|
140 |
+
language
|
141 |
+
)
|
142 |
+
|
143 |
+
return transcript_msg, transcript_file, formatted_quiz, quiz_file, json_file
|