| import gradio as gr |
| import pandas as pd |
| from sentence_transformers import SentenceTransformer |
|
|
| |
| def processar_planilha(planilha_caminho): |
| try: |
| |
| df = pd.read_excel(planilha_caminho) |
|
|
| |
| if "IA Analysis" not in df.columns: |
| return "Erro: A coluna 'IA Analysis' não foi encontrada na planilha." |
|
|
| |
| frases = df["IA Analysis"].dropna().tolist() |
|
|
| if not frases: |
| return "Erro: A coluna 'IA Analysis' está vazia." |
|
|
| |
| modelo = SentenceTransformer('all-MiniLM-L6-v2') |
| vetores = modelo.encode(frases) |
|
|
| |
| df["Vetores"] = [str(vetor.tolist()) for vetor in vetores] |
|
|
| |
| output_path = "planilha_processada.xlsx" |
| df.to_excel(output_path, index=False) |
|
|
| return f"Processamento concluído! Foram analisadas {len(frases)} frases.", output_path |
| |
| except Exception as e: |
| return f"Erro ao processar a planilha: {str(e)}", None |
|
|
| |
| with gr.Blocks() as demo: |
| |
| planilha_input = gr.File(label="Carregar Planilha (Excel)", type="filepath") |
| |
| |
| submit_button = gr.Button("Enviar") |
| |
| |
| clear_button = gr.Button("Limpar") |
| |
| |
| output_message = gr.Textbox(label="Mensagem de Status") |
| |
| |
| download_button = gr.File(label="Baixar Planilha Processada") |
| |
| |
| def process_and_return(planilha_caminho): |
| mensagem, output_path = processar_planilha(planilha_caminho) |
| if output_path: |
| return mensagem, output_path |
| return mensagem, None |
|
|
| submit_button.click( |
| fn=process_and_return, |
| inputs=[planilha_input], |
| outputs=[output_message, download_button], |
| ) |
| |
| |
| clear_button.click( |
| fn=lambda: ("", None), |
| inputs=[], |
| outputs=[output_message, download_button], |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch() |
|
|