Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,8 +43,8 @@ function refresh() {
|
|
| 43 |
# ===============================
|
| 44 |
# Azure OpenAI setup
|
| 45 |
# ===============================
|
| 46 |
-
os.environ["AZURE_OPENAI_ENDPOINT"] =
|
| 47 |
-
os.environ["AZURE_OPENAI_API_KEY"] =
|
| 48 |
|
| 49 |
client = AzureOpenAI(
|
| 50 |
api_version="2023-05-15",
|
|
@@ -249,7 +249,8 @@ def combine_all_data(file_paths, pdf_file, user_fields):
|
|
| 249 |
final_df = final_df.reindex(columns=desired_columns)
|
| 250 |
|
| 251 |
final_df.to_csv("merged_all_data.csv", index=False)
|
| 252 |
-
|
|
|
|
| 253 |
|
| 254 |
# ===============================
|
| 255 |
# Gradio Interface Function
|
|
@@ -271,11 +272,11 @@ def process_data(files, pdf_file, field_text):
|
|
| 271 |
pdf_path = pdf_file.name if pdf_file is not None else None
|
| 272 |
|
| 273 |
try:
|
| 274 |
-
final_df = combine_all_data(file_paths, pdf_path, user_fields)
|
| 275 |
except Exception as e:
|
| 276 |
return f"Error during processing: {e}"
|
| 277 |
|
| 278 |
-
return final_df
|
| 279 |
|
| 280 |
with open("Frame 1.png", "rb") as logo_file:
|
| 281 |
base64_logo = base64.b64encode(logo_file.read()).decode("utf-8")
|
|
@@ -302,15 +303,15 @@ with gr.Blocks(theme=basetheme,js=js_func,fill_height=True) as demo:
|
|
| 302 |
gr.Interface(
|
| 303 |
fn=process_data,
|
| 304 |
inputs=[
|
| 305 |
-
gr.File(label="Upload CSV/Excel files", file_count="multiple"),
|
| 306 |
-
gr.File(label="Upload PDF file (optional)"),
|
| 307 |
gr.Textbox(
|
| 308 |
label="Desired Fields (one per line, use 'Field Name: Description' format)",
|
| 309 |
placeholder="Example:\nName: Full name\nDOB: Date of birth\nAddress: Full address\n",
|
| 310 |
lines=6,
|
| 311 |
),
|
| 312 |
],
|
| 313 |
-
outputs=gr.Dataframe(label="Final Merged Data"),
|
| 314 |
description=(
|
| 315 |
"Upload one or more CSV/Excel files, optionally a PDF file, and enter your desired fields below. "
|
| 316 |
"Type each field on a new line in the format:\n"
|
|
|
|
| 43 |
# ===============================
|
| 44 |
# Azure OpenAI setup
|
| 45 |
# ===============================
|
| 46 |
+
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://bt-openai-service.openai.azure.com/"
|
| 47 |
+
os.environ["AZURE_OPENAI_API_KEY"] = "2X63USY3YggblwdI9KiOUnCM63MFZhXGSX4Np1eBu8NsjHNeWibRJQQJ99AKACYeBjFXJ3w3AAABACOGYrgW" # Replace with your actual API key
|
| 48 |
|
| 49 |
client = AzureOpenAI(
|
| 50 |
api_version="2023-05-15",
|
|
|
|
| 249 |
final_df = final_df.reindex(columns=desired_columns)
|
| 250 |
|
| 251 |
final_df.to_csv("merged_all_data.csv", index=False)
|
| 252 |
+
absolute_path = os.path.abspath("merged_all_data.csv")
|
| 253 |
+
return final_df,absolute_path
|
| 254 |
|
| 255 |
# ===============================
|
| 256 |
# Gradio Interface Function
|
|
|
|
| 272 |
pdf_path = pdf_file.name if pdf_file is not None else None
|
| 273 |
|
| 274 |
try:
|
| 275 |
+
final_df, absolute_path = combine_all_data(file_paths, pdf_path, user_fields)
|
| 276 |
except Exception as e:
|
| 277 |
return f"Error during processing: {e}"
|
| 278 |
|
| 279 |
+
return final_df, absolute_path
|
| 280 |
|
| 281 |
with open("Frame 1.png", "rb") as logo_file:
|
| 282 |
base64_logo = base64.b64encode(logo_file.read()).decode("utf-8")
|
|
|
|
| 303 |
gr.Interface(
|
| 304 |
fn=process_data,
|
| 305 |
inputs=[
|
| 306 |
+
gr.File(label="Upload CSV/Excel files", file_count="multiple",file_types=[".csv", ".xlsx", ".xls"]),
|
| 307 |
+
gr.File(label="Upload PDF file (optional)", file_types=[".pdf"]),
|
| 308 |
gr.Textbox(
|
| 309 |
label="Desired Fields (one per line, use 'Field Name: Description' format)",
|
| 310 |
placeholder="Example:\nName: Full name\nDOB: Date of birth\nAddress: Full address\n",
|
| 311 |
lines=6,
|
| 312 |
),
|
| 313 |
],
|
| 314 |
+
outputs=[gr.Dataframe(label="Final Merged Data"),gr.File(label="Download CSV")],
|
| 315 |
description=(
|
| 316 |
"Upload one or more CSV/Excel files, optionally a PDF file, and enter your desired fields below. "
|
| 317 |
"Type each field on a new line in the format:\n"
|