ABDALLAH31 commited on
Commit
5fc16ba
·
verified ·
1 Parent(s): fe714c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -1,11 +1,10 @@
1
- import os
2
  import requests
 
3
 
4
- # Hugging Face API URL for the LegalBERT model
5
  API_URL = "https://api-inference.huggingface.co/models/nlpaueb/legal-bert-base-uncased"
6
- API_KEY = os.getenv("Contract_Risk") # Fetch the API key securely from environment variables
7
 
8
- # Function to send contract to Hugging Face API and get analysis results
9
  def analyze_contract(contract_text):
10
  headers = {
11
  "Authorization": f"Bearer {API_KEY}",
@@ -17,15 +16,10 @@ def analyze_contract(contract_text):
17
  try:
18
  # Send the contract text to Hugging Face for analysis
19
  response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
20
- response.raise_for_status() # Raise an exception for invalid responses (4xx/5xx)
21
 
22
- # Parse the response from Hugging Face
23
  result = response.json()
24
 
25
- # Print the raw response for debugging
26
- print("Raw Response from Hugging Face:", result)
27
-
28
- # Extracting the risk score, high-risk clauses, and the risk map URL (if available)
29
  overall_risk_score = result.get('overall_score', 'No score available')
30
  high_risk_clauses = result.get('high_risk_clauses', 'No high-risk clauses detected')
31
  risk_map_url = result.get('risk_map_url', 'No risk map available')
@@ -41,3 +35,22 @@ def analyze_contract(contract_text):
41
  except Exception as e:
42
  print(f"Unexpected error: {e}")
43
  return f"Unexpected error: {e}", "", ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  import requests
3
+ import os
4
 
 
5
  API_URL = "https://api-inference.huggingface.co/models/nlpaueb/legal-bert-base-uncased"
6
+ API_KEY = os.getenv("Contract_Risk")
7
 
 
8
  def analyze_contract(contract_text):
9
  headers = {
10
  "Authorization": f"Bearer {API_KEY}",
 
16
  try:
17
  # Send the contract text to Hugging Face for analysis
18
  response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
19
+ response.raise_for_status()
20
 
 
21
  result = response.json()
22
 
 
 
 
 
23
  overall_risk_score = result.get('overall_score', 'No score available')
24
  high_risk_clauses = result.get('high_risk_clauses', 'No high-risk clauses detected')
25
  risk_map_url = result.get('risk_map_url', 'No risk map available')
 
35
  except Exception as e:
36
  print(f"Unexpected error: {e}")
37
  return f"Unexpected error: {e}", "", ""
38
+
39
+ def create_ui():
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown("### Contract Risk Analyzer")
42
+ with gr.Row():
43
+ contract_input = gr.Textbox(label="Contract Text", placeholder="Paste contract text here", lines=10)
44
+ with gr.Row():
45
+ analyze_button = gr.Button("Analyze Contract")
46
+ with gr.Row():
47
+ risk_score_output = gr.Textbox(label="Overall Risk Score", interactive=False)
48
+ high_risk_clauses_output = gr.Textbox(label="High Risk Clauses", interactive=False)
49
+ risk_map_url_output = gr.Textbox(label="Risk Map URL", interactive=False)
50
+
51
+ analyze_button.click(fn=analyze_contract, inputs=contract_input, outputs=[risk_score_output, high_risk_clauses_output, risk_map_url_output])
52
+
53
+ demo.launch()
54
+
55
+ if __name__ == "__main__":
56
+ create_ui()