anuradhakoppala's picture
Update app.py
70bcbee verified
import gradio as gr
import requests
import os
from dotenv import load_dotenv
load_dotenv()
API_URL = os.getenv("API_URL")
def summarize_contract(file):
try:
with open(file.name, 'rb') as f:
files = {'file': (file.name, f)}
response = requests.post(API_URL, files=files, timeout=15)
if response.status_code != 200:
return f"❌ Error: {response.json().get('error', 'Unknown error')}", "", "", "", "", "", ""
data = response.json()
return "βœ… Summary generated successfully", data["parties"], data["startDate"], data["endDate"], data["paymentTerms"], data["obligations"], data["terminationClause"]
except requests.exceptions.ConnectionError:
return "❌ Backend server is not running at the specified API URL.", "", "", "", "", "", ""
except requests.exceptions.Timeout:
return "❌ Server timed out. Try with a smaller file.", "", "", "", "", "", ""
except Exception as e:
return f"❌ Exception: {str(e)}", "", "", "", "", "", ""
with gr.Blocks() as demo:
gr.Markdown("## πŸ“„ Contract Analyzer (Multi-File Support)")
file = gr.File(label="Upload Contract File", file_types=[
".csv", ".xls", ".xlsx", ".docx", ".pdf", ".jpg", ".jpeg", ".png"
])
submit = gr.Button("Summarize Contract")
result = gr.Textbox(label="Status")
parties = gr.Textbox(label="Parties Involved")
start_date = gr.Textbox(label="Start Date")
end_date = gr.Textbox(label="End Date")
payment = gr.Textbox(label="Payment Terms")
obligations = gr.Textbox(label="Obligations")
termination = gr.Textbox(label="Termination Clause")
submit.click(fn=summarize_contract, inputs=file,
outputs=[result, parties, start_date, end_date, payment, obligations, termination])
if __name__ == "__main__":
demo.launch()