ABDALLAH31 commited on
Commit
113b3f5
·
verified ·
1 Parent(s): 1462c54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -18,21 +18,26 @@ def classify_clauses(text_input):
18
  # Split input into clauses
19
  clauses = [clause.strip() for clause in text_input.strip().split('\n') if clause.strip()]
20
 
 
21
  scores = []
22
  for clause in clauses:
23
  result = classifier(clause, labels)
24
 
25
- # Print the result to check the structure
26
- print(f"Result for clause: '{clause}'")
27
- print(result) # Print the result to check its structure
28
-
29
- # Ensure the 'scores' key exists in the result
30
  if 'scores' in result:
31
  scores.append(result['scores'])
 
 
 
 
 
32
  else:
33
- # Handle the case where 'scores' key is missing
34
- print(f"Error: No scores found for clause: '{clause}'")
35
  scores.append([0, 0, 0]) # Default to no risk if 'scores' is missing
 
 
 
 
 
36
 
37
  scores_array = np.array(scores)
38
 
@@ -50,12 +55,12 @@ def classify_clauses(text_input):
50
  plt.ylabel("Clauses")
51
  plt.tight_layout()
52
 
53
- # Save and return the plot
54
  plot_path = "heatmap.png"
55
  plt.savefig(plot_path)
56
  plt.close()
57
 
58
- return plot_path
59
 
60
  # Function to analyze contract and generate results
61
  def analyze_contract(file):
@@ -65,7 +70,7 @@ def analyze_contract(file):
65
 
66
  # Split the text into clauses
67
  clauses = simple_clause_split(text)
68
- results = classify_clauses("\n".join(clauses)) # Classify the clauses
69
 
70
  # Calculate the overall risk score
71
  overall_score = sum(r['risk_score'] for r in results) / len(results) if results else 0
@@ -89,7 +94,7 @@ def analyze_contract(file):
89
  "overall_score": overall_score
90
  })
91
 
92
- return f"Overall Risk Score: {overall_score:.2f}", highlight_output, report_path, results['heatmap']
93
 
94
  # Gradio interface
95
  demo = gr.Interface(
 
18
  # Split input into clauses
19
  clauses = [clause.strip() for clause in text_input.strip().split('\n') if clause.strip()]
20
 
21
+ results = []
22
  scores = []
23
  for clause in clauses:
24
  result = classifier(clause, labels)
25
 
26
+ # Extract scores and store the results
 
 
 
 
27
  if 'scores' in result:
28
  scores.append(result['scores'])
29
+ results.append({
30
+ 'clause': clause,
31
+ 'risk_score': result['scores'][0], # High-risk score
32
+ 'risk_level': labels[result['scores'].index(max(result['scores']))] # Determine risk level
33
+ })
34
  else:
 
 
35
  scores.append([0, 0, 0]) # Default to no risk if 'scores' is missing
36
+ results.append({
37
+ 'clause': clause,
38
+ 'risk_score': 0,
39
+ 'risk_level': 'low'
40
+ })
41
 
42
  scores_array = np.array(scores)
43
 
 
55
  plt.ylabel("Clauses")
56
  plt.tight_layout()
57
 
58
+ # Save and return the plot path
59
  plot_path = "heatmap.png"
60
  plt.savefig(plot_path)
61
  plt.close()
62
 
63
+ return results, plot_path
64
 
65
  # Function to analyze contract and generate results
66
  def analyze_contract(file):
 
70
 
71
  # Split the text into clauses
72
  clauses = simple_clause_split(text)
73
+ results, heatmap_path = classify_clauses("\n".join(clauses)) # Classify the clauses
74
 
75
  # Calculate the overall risk score
76
  overall_score = sum(r['risk_score'] for r in results) / len(results) if results else 0
 
94
  "overall_score": overall_score
95
  })
96
 
97
+ return f"Overall Risk Score: {overall_score:.2f}", highlight_output, report_path, heatmap_path
98
 
99
  # Gradio interface
100
  demo = gr.Interface(