Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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,
|
| 6 |
"""
|
| 7 |
Processes an uploaded file, extracts its text content, and saves it to the database.
|
| 8 |
|
|
@@ -19,7 +19,7 @@ def process_file(file, topics):
|
|
| 19 |
----------
|
| 20 |
file : object
|
| 21 |
The uploaded file object. The file's name (`file.name`) is used to determine the file path.
|
| 22 |
-
|
| 23 |
A list of topics or a single topic string associated with the file. These are saved to the database along with the file content.
|
| 24 |
|
| 25 |
Returns:
|
|
@@ -43,7 +43,7 @@ def process_file(file, topics):
|
|
| 43 |
|
| 44 |
# Spl
|
| 45 |
# Save chunks to database
|
| 46 |
-
save_to_db(text,
|
| 47 |
|
| 48 |
return f"File processed successfully! file saved to the database."
|
| 49 |
except Exception as e:
|
|
@@ -54,11 +54,11 @@ 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 |
-
|
| 58 |
submit_button = gr.Button("Upload and Process")
|
| 59 |
output_text = gr.Textbox(label="Status")
|
| 60 |
|
| 61 |
-
submit_button.click(process_file, inputs=[file_input,
|
| 62 |
|
| 63 |
# Launch the app
|
| 64 |
demo.launch()
|
|
|
|
| 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 |
|
|
|
|
| 19 |
----------
|
| 20 |
file : object
|
| 21 |
The uploaded file object. The file's name (`file.name`) is used to determine the file path.
|
| 22 |
+
topic : list or str
|
| 23 |
A list of topics or a single topic string associated with the file. These are saved to the database along with the file content.
|
| 24 |
|
| 25 |
Returns:
|
|
|
|
| 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:
|
|
|
|
| 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")
|
| 60 |
|
| 61 |
+
submit_button.click(process_file, inputs=[file_input, topic_input], outputs=output_text)
|
| 62 |
|
| 63 |
# Launch the app
|
| 64 |
demo.launch()
|