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