Spaces:
Sleeping
Sleeping
| 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() | |