Код: Выделить всё
import gradio as gr
from time import sleep
import pandas as pd
import random
css = """
.custom-file-input {
height: 50px;
}
"""
with gr.Blocks(css=css) as ui:
gr.Markdown(value='#### File for analysis:')
with gr.Row():
file_input = gr.File(label="Excel or CSV file", elem_classes="custom-file-input", file_count=1)
analyze_button = gr.Button("Analyze", scale=0)
gr.Markdown(value='### Progress:')
progress_output = gr.Markdown()
status_text = gr.Textbox(interactive=False, show_label=False, visible=True)
result_file = gr.File(label="Result", interactive=False)
@analyze_button.click(inputs=file_input)
def process_file(file):
# Simulate file processing and progress updates
progress = gr.Progress()
progress(0, desc='0%')
df = pd.read_excel(file.name)
n_lines = df.shape[0]
for i in range(n_lines):
# sleep(0.01) # Simulate some processing time
df.iloc[i]['Target'] = random.choice(['MOROCCO', 'PRODUCT SKI', 'FINANCE', 'DOMESTIC'])
progress((i + 1) / n_lines, desc=f'{int((i + 1) / n_lines * 100)}%')
progress(1, desc='100%')
output_file = "processed_file.xlsx"
df.to_excel(output_file, index=False)
ui.launch()
Чтобы воспроизвести: поместите любой файл Excel с несколькими строками текста в интерфейс градиента и нажмите кнопку «Анализ» справа от него.
Подробнее здесь: https://stackoverflow.com/questions/786 ... ter-must-b