Update file_module.py
Browse files- file_module.py +30 -13
file_module.py
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def file_dashboard():
|
|
@@ -26,24 +32,35 @@ def file_dashboard():
|
|
| 26 |
with gr.Tab("💬 Answer to Your Question"):
|
| 27 |
answer_output = gr.Textbox(label="Answer", lines=4, interactive=False)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
file_upload.change(
|
| 38 |
-
fn=
|
| 39 |
inputs=[file_upload],
|
| 40 |
-
outputs=[summary_output, flashcard_output, quiz_output
|
| 41 |
)
|
| 42 |
|
| 43 |
question_box.change(
|
| 44 |
-
fn=
|
| 45 |
-
inputs=[question_box],
|
| 46 |
-
outputs=[
|
| 47 |
)
|
| 48 |
|
| 49 |
return file_panel
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from file_utils import (
|
| 4 |
+
extract_text_from_file,
|
| 5 |
+
generate_summary,
|
| 6 |
+
generate_flashcards,
|
| 7 |
+
generate_quiz,
|
| 8 |
+
answer_question
|
| 9 |
+
)
|
| 10 |
|
| 11 |
|
| 12 |
def file_dashboard():
|
|
|
|
| 32 |
with gr.Tab("💬 Answer to Your Question"):
|
| 33 |
answer_output = gr.Textbox(label="Answer", lines=4, interactive=False)
|
| 34 |
|
| 35 |
+
text_state = gr.State("")
|
| 36 |
+
|
| 37 |
+
def handle_file_upload(file):
|
| 38 |
+
text = extract_text_from_file(file)
|
| 39 |
+
if not text or "Unsupported file type" in text:
|
| 40 |
+
return text, "", "", ""
|
| 41 |
+
|
| 42 |
+
summary = generate_summary(text)
|
| 43 |
+
flashcards = generate_flashcards(text)
|
| 44 |
+
quiz = generate_quiz(text)
|
| 45 |
+
return text, summary, flashcards, quiz
|
| 46 |
+
|
| 47 |
+
def handle_question(text, question):
|
| 48 |
+
if not text.strip():
|
| 49 |
+
return "Please upload a file first."
|
| 50 |
+
if not question.strip():
|
| 51 |
+
return "Please enter a question."
|
| 52 |
+
return answer_question(text, question)
|
| 53 |
|
| 54 |
file_upload.change(
|
| 55 |
+
fn=handle_file_upload,
|
| 56 |
inputs=[file_upload],
|
| 57 |
+
outputs=[text_state, summary_output, flashcard_output, quiz_output]
|
| 58 |
)
|
| 59 |
|
| 60 |
question_box.change(
|
| 61 |
+
fn=handle_question,
|
| 62 |
+
inputs=[text_state, question_box],
|
| 63 |
+
outputs=[answer_output]
|
| 64 |
)
|
| 65 |
|
| 66 |
return file_panel
|