Spaces:
Sleeping
Sleeping
File size: 8,518 Bytes
3add489 ffe0e82 2bd5429 3add489 2bd5429 3add489 2bd5429 3add489 2bd5429 3add489 2bd5429 3add489 2bd5429 3add489 2bd5429 3add489 2bd5429 3add489 |
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 |
import os
import gradio as gr
import tempfile
from src.mainFunctions import combined_process_video_file, process_pdf_document, process_docx_document, process_audio_document
from src.video_processing import process_video_file
ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY", None)
GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY', None)
CLAUDE_API_KEY = os.environ.get('CLAUDE_API_KEY', None)
with gr.Blocks(title="Document to Quiz Generator") as app:
gr.Markdown("# Document & Media => Quiz")
gr.Markdown("Upload a video, audio, PDF, or Word document to 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")
# PDF Tab
with gr.TabItem("Upload PDF"):
with gr.Row():
with gr.Column():
pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"])
process_pdf_button = gr.Button("Process PDF & Generate Quiz")
with gr.Column():
pdf_status_output = gr.Textbox(label="PDF Processing Status")
pdf_text_file_output = gr.File(label="Extracted Text File")
with gr.Row():
with gr.Column():
pdf_quiz_output = gr.Textbox(
label="Generated Quiz",
lines=15
)
with gr.Row():
pdf_quiz_file_output = gr.File(label="Download Quiz Text")
pdf_json_file_output = gr.File(label="Download Quiz JSON")
# Word Document Tab
with gr.TabItem("Upload Word Document"):
with gr.Row():
with gr.Column():
docx_input = gr.File(label="Upload Word Document", file_types=[".docx"])
process_docx_button = gr.Button("Process Word Document & Generate Quiz")
with gr.Column():
docx_status_output = gr.Textbox(label="Word Document Processing Status")
docx_text_file_output = gr.File(label="Extracted Text File")
with gr.Row():
with gr.Column():
docx_quiz_output = gr.Textbox(
label="Generated Quiz",
lines=15
)
with gr.Row():
docx_quiz_file_output = gr.File(label="Download Quiz Text")
docx_json_file_output = gr.File(label="Download Quiz JSON")
# Audio Tab
with gr.TabItem("Upload Audio"):
with gr.Row():
with gr.Column():
audio_input = gr.Audio(label="Upload Audio", type="filepath")
process_audio_button = gr.Button("Process Audio & 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_quiz_output = gr.Textbox(
label="Generated Quiz",
lines=15
)
with gr.Row():
audio_quiz_file_output = gr.File(label="Download Quiz Text")
audio_json_file_output = gr.File(label="Download Quiz JSON")
# Connect video processing
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
]
)
# Connect PDF processing
process_pdf_button.click(
fn=process_pdf_document,
inputs=[
pdf_input,
gemini_api_key,
claude_api_key,
course_name,
section_name,
lesson_name,
language_selector
],
outputs=[
pdf_status_output,
pdf_text_file_output,
pdf_quiz_output,
pdf_quiz_file_output,
pdf_json_file_output
]
)
process_docx_button.click(
fn=process_docx_document,
inputs=[
docx_input,
gemini_api_key,
claude_api_key,
course_name,
section_name,
lesson_name,
language_selector
],
outputs=[
docx_status_output,
docx_text_file_output,
docx_quiz_output,
docx_quiz_file_output,
docx_json_file_output
]
)
process_audio_button.click(
fn=process_audio_document,
inputs=[
audio_input,
elevenlabs_api_key,
model_id,
gemini_api_key,
claude_api_key,
course_name,
section_name,
lesson_name,
language_selector
],
outputs=[
audio_status_output,
audio_transcript_file_output,
audio_quiz_output,
audio_quiz_file_output,
audio_json_file_output
]
)
if __name__ == "__main__":
app.launch(share=True, debug=True) |