pmt / app.py
Gainward777's picture
Upload 4 files
d3c331c verified
import gradio as gr
from Funcs import new_run
import pandas as pd
import tempfile
def process_files(file1, file2, threshold):
row_items=pd.read_csv(file2, sep='\t')
row_products=pd.read_csv(file1, sep='\t', on_bad_lines='skip')
df, items, products= new_run(row_products, row_items, threshold)
# Создаём временный CSV файл для сохранения результата
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as tmp:
output_csv = tmp.name
df.to_csv(output_csv, sep='\t', index=False)
return output_csv
# Определяем пользовательский интерфейс с помощью gr.Blocks
with gr.Blocks() as demo:
gr.Markdown("## Обработка CSV файлов")
with gr.Row():
# Используем type="filepath", чтобы получить путь к файлу
file_input1 = gr.File(label="Products", type="filepath", file_types=[".csv"])
file_input2 = gr.File(label="Items", type="filepath", file_types=[".csv"])
threshold_input = gr.Slider(minimum=0, maximum=100, step=1, label="Threshold", value=50)
process_button = gr.Button("Обработать файлы")
output_file = gr.File(label="Скачать результат (CSV)")
# При нажатии кнопки вызывается функция process_files
process_button.click(fn=process_files, inputs=[file_input1, file_input2, threshold_input], outputs=output_file)
demo.launch()