final_bert / app.py
advaitidalvi's picture
Upload 4 files
61f06ab verified
Raw
History Blame Contribute Delete
1.76 kB
import os
import gradio as gr
import pandas as pd
import tempfile
from agent import run_agent
def _write_tmp(content, name):
with tempfile.NamedTemporaryFile(mode="w", suffix=name, delete=False) as f:
f.write(content)
return f.name
def run_pipeline(file_obj):
if not file_obj: return "Upload a file", None, None, None, None, None, None
df = pd.read_csv(file_obj.name)
rows = df.to_dict('records')
state = None
for log in run_agent(rows):
if isinstance(log, str):
yield log, None, None, None, None, None
else:
state = log
yield (
"Done",
pd.DataFrame(state.title_summary),
pd.DataFrame(state.abstract_summary),
pd.DataFrame(state.pajais_map.get("MAPPED", [])),
_write_tmp(state.comparison_csv, "comparison.csv"),
_write_tmp(state.taxonomy_json, "taxonomy.json")
)
with gr.Blocks(title="Agentic Topic Modeller") as demo:
gr.Markdown("# ◈ AGENTIC TOPIC MODELLER (Mistral Version)")
with gr.Row():
file_input = gr.File(label="Upload CSV")
run_btn = gr.Button("Run Pipeline", variant="primary")
logs = gr.Textbox(label="Agent Logs", lines=5)
with gr.Tabs():
with gr.Tab("Title Topics"):
t_out = gr.Dataframe()
with gr.Tab("Abstract Topics"):
a_out = gr.Dataframe()
with gr.Tab("PAJAIS Map"):
p_out = gr.Dataframe()
with gr.Row():
dl_csv = gr.File(label="Download Comparison")
dl_json = gr.File(label="Download Taxonomy")
run_btn.click(run_pipeline, inputs=[file_input], outputs=[logs, t_out, a_out, p_out, dl_csv, dl_json])
if __name__ == "__main__":
demo.launch()