ankban commited on
Commit
e79e5f0
·
verified ·
1 Parent(s): 4aaf33c

Update file_module.py

Browse files
Files changed (1) hide show
  1. file_module.py +30 -13
file_module.py CHANGED
@@ -1,6 +1,12 @@
1
  import gradio as gr
2
  import os
3
- from tempfile import NamedTemporaryFile
 
 
 
 
 
 
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
- def placeholder_logic(file, question):
30
- # Placeholder logic until GPT + parsing is added
31
- summary = "This is a summary of your uploaded content."
32
- flashcards = "Flashcard 1: Question? | Answer.\nFlashcard 2: Question? | Answer."
33
- quiz = "1. What is...?\n2. Explain..."
34
- answer = f"You asked: {question}\nHere's a helpful answer from your content."
35
- return summary, flashcards, quiz, answer
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  file_upload.change(
38
- fn=lambda file: placeholder_logic(file, ""),
39
  inputs=[file_upload],
40
- outputs=[summary_output, flashcard_output, quiz_output, answer_output]
41
  )
42
 
43
  question_box.change(
44
- fn=lambda question: placeholder_logic(None, question),
45
- inputs=[question_box],
46
- outputs=[summary_output, flashcard_output, quiz_output, answer_output]
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