Spaces:
Sleeping
Sleeping
import gradio as gr | |
from preprocessing import read_file, save_to_db | |
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() |