Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from preprocessing import read_file, save_to_db
|
3 |
+
|
4 |
+
def process_file(file, topics):
|
5 |
+
"""Process uploaded file and save to database."""
|
6 |
+
try:
|
7 |
+
# Read the file content
|
8 |
+
file_path = file.name
|
9 |
+
text = read_file(file_path)
|
10 |
+
|
11 |
+
# Spl
|
12 |
+
# Save chunks to database
|
13 |
+
save_to_db(text, topics)
|
14 |
+
|
15 |
+
return f"File processed successfully! file saved to the database."
|
16 |
+
except Exception as e:
|
17 |
+
return f"Error processing file: {str(e)}"
|
18 |
+
|
19 |
+
# Define Gradio interface
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
gr.Markdown("# Dataset Upload Interface")
|
22 |
+
with gr.Row():
|
23 |
+
file_input = gr.File(label="Upload File (.docx or .txt)")
|
24 |
+
topics_input = gr.Textbox(label="Topics (comma-separated)", placeholder="e.g., science, technology, law, medicin")
|
25 |
+
submit_button = gr.Button("Upload and Process")
|
26 |
+
output_text = gr.Textbox(label="Status")
|
27 |
+
|
28 |
+
submit_button.click(process_file, inputs=[file_input, topics_input], outputs=output_text)
|
29 |
+
|
30 |
+
# Launch the app
|
31 |
+
demo.launch()
|