Danielrahmai1991 commited on
Commit
033e470
·
verified ·
1 Parent(s): a2808a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from database import save_to_db
3
  from preprocessing import read_file
4
 
5
- def process_file(file, topic):
6
  """
7
  Processes an uploaded file, extracts its text content, and saves it to the database.
8
 
@@ -36,24 +36,25 @@ def process_file(file, topic):
36
  >>> process_file(unsupported_file, ["Science"])
37
  'Error processing file: Unsupported file format. Only .docx, .txt, and .pdf are allowed.'
38
  """
39
- try:
40
- # Read the file content
41
- file_path = file.name
42
- text = read_file(file_path)
43
-
44
- # Spl
45
- # Save chunks to database
46
- save_to_db([text], topic)
47
-
48
- return f"File processed successfully! file saved to the database."
49
- except Exception as e:
50
- return f"Error processing file: {str(e)}"
 
51
 
52
  # Define Gradio interface
53
  with gr.Blocks() as demo:
54
  gr.Markdown("# Dataset Upload Interface")
55
  with gr.Row():
56
- file_input = gr.File(label="Upload File (.docx or .txt or .pdf)")
57
  topic_input = gr.Textbox(label="Topics (comma-separated)", placeholder="e.g., science, technology, law, medicin")
58
  submit_button = gr.Button("Upload and Process")
59
  output_text = gr.Textbox(label="Status")
 
2
  from database import save_to_db
3
  from preprocessing import read_file
4
 
5
+ def process_file(files, topic):
6
  """
7
  Processes an uploaded file, extracts its text content, and saves it to the database.
8
 
 
36
  >>> process_file(unsupported_file, ["Science"])
37
  'Error processing file: Unsupported file format. Only .docx, .txt, and .pdf are allowed.'
38
  """
39
+ for file in files:
40
+ try:
41
+ # Read the file content
42
+ file_path = file.name
43
+ text = read_file(file_path)
44
+
45
+ # Spl
46
+ # Save chunks to database
47
+ save_to_db([text], topic)
48
+
49
+ return f"File {file_path} processed successfully! file saved to the database."
50
+ except Exception as e:
51
+ return f"Error processing for file {file_path}: {str(e)}"
52
 
53
  # Define Gradio interface
54
  with gr.Blocks() as demo:
55
  gr.Markdown("# Dataset Upload Interface")
56
  with gr.Row():
57
+ file_input = gr.File(label="Upload File (.docx or .txt or .pdf)", file_count="multiple")
58
  topic_input = gr.Textbox(label="Topics (comma-separated)", placeholder="e.g., science, technology, law, medicin")
59
  submit_button = gr.Button("Upload and Process")
60
  output_text = gr.Textbox(label="Status")