Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import tempfile, os
|
| 3 |
-
from pipeline import run_pipeline
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
|
| 6 |
DATASET_PATH = "dataset.csv"
|
| 7 |
|
| 8 |
def analyze_pdf(file):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 10 |
file_path = os.path.join(tmpdirname, file.name)
|
| 11 |
with open(file_path, "wb") as f:
|
| 12 |
f.write(file.read())
|
|
|
|
|
|
|
| 13 |
results = run_pipeline(tmpdirname)
|
| 14 |
|
| 15 |
# Save to dataset.csv
|
|
@@ -22,11 +28,13 @@ def analyze_pdf(file):
|
|
| 22 |
|
| 23 |
return results.to_dict(orient="records")
|
| 24 |
|
|
|
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=analyze_pdf,
|
| 27 |
-
inputs=gr.File(file_types=[".pdf"]),
|
| 28 |
-
outputs=gr.JSON(),
|
| 29 |
-
title="SC API"
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tempfile, os
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
+
from pipeline import run_pipeline
|
| 5 |
|
| 6 |
DATASET_PATH = "dataset.csv"
|
| 7 |
|
| 8 |
def analyze_pdf(file):
|
| 9 |
+
if file is None:
|
| 10 |
+
return {"error": "No file uploaded."}
|
| 11 |
+
|
| 12 |
+
# Save the uploaded file to a temporary folder
|
| 13 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 14 |
file_path = os.path.join(tmpdirname, file.name)
|
| 15 |
with open(file_path, "wb") as f:
|
| 16 |
f.write(file.read())
|
| 17 |
+
|
| 18 |
+
# Run your pipeline
|
| 19 |
results = run_pipeline(tmpdirname)
|
| 20 |
|
| 21 |
# Save to dataset.csv
|
|
|
|
| 28 |
|
| 29 |
return results.to_dict(orient="records")
|
| 30 |
|
| 31 |
+
# Gradio interface
|
| 32 |
iface = gr.Interface(
|
| 33 |
fn=analyze_pdf,
|
| 34 |
+
inputs=gr.File(file_types=[".pdf"], label="Upload PDF"),
|
| 35 |
+
outputs=gr.JSON(label="Output"),
|
| 36 |
+
title="SC API",
|
| 37 |
+
description="Upload PDF files to process ESG scores."
|
| 38 |
)
|
| 39 |
|
| 40 |
iface.launch()
|