Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import matplotlib.pyplot as plt
|
| 3 |
-
import seaborn as sns
|
| 4 |
import numpy as np
|
| 5 |
-
import
|
| 6 |
|
|
|
|
| 7 |
def generate_heatmap(results):
|
| 8 |
# If results is a string, process it into a list of dicts (or just use the text as is)
|
| 9 |
if isinstance(results, str): # Check if results is a string
|
|
@@ -18,7 +17,7 @@ def generate_heatmap(results):
|
|
| 18 |
risk_map = {'High': 3, 'Medium': 2, 'Low': 1}
|
| 19 |
risk_values = [risk_map.get(risk, 0) for risk in risk_levels]
|
| 20 |
|
| 21 |
-
# Create a heatmap
|
| 22 |
fig = go.Figure(data=go.Heatmap(
|
| 23 |
z=[risk_values], # The data for the heatmap
|
| 24 |
x=clauses, # Clause text as the x-axis labels
|
|
@@ -31,8 +30,20 @@ def generate_heatmap(results):
|
|
| 31 |
fig.update_layout(
|
| 32 |
title="Contract Risk Heatmap",
|
| 33 |
xaxis_title="Clause",
|
| 34 |
-
yaxis_title="Risk Level"
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
return fig.to_html(full_html=False)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
|
| 5 |
+
# Mock function to generate heatmap from contract analysis results
|
| 6 |
def generate_heatmap(results):
|
| 7 |
# If results is a string, process it into a list of dicts (or just use the text as is)
|
| 8 |
if isinstance(results, str): # Check if results is a string
|
|
|
|
| 17 |
risk_map = {'High': 3, 'Medium': 2, 'Low': 1}
|
| 18 |
risk_values = [risk_map.get(risk, 0) for risk in risk_levels]
|
| 19 |
|
| 20 |
+
# Create a heatmap using Plotly
|
| 21 |
fig = go.Figure(data=go.Heatmap(
|
| 22 |
z=[risk_values], # The data for the heatmap
|
| 23 |
x=clauses, # Clause text as the x-axis labels
|
|
|
|
| 30 |
fig.update_layout(
|
| 31 |
title="Contract Risk Heatmap",
|
| 32 |
xaxis_title="Clause",
|
| 33 |
+
yaxis_title="Risk Level",
|
| 34 |
+
xaxis=dict(tickmode='array', tickvals=range(len(clauses)), ticktext=[clause[:20] + '...' if len(clause) > 20 else clause for clause in clauses]) # Truncate clauses if too long
|
| 35 |
)
|
| 36 |
|
| 37 |
return fig.to_html(full_html=False)
|
| 38 |
|
| 39 |
+
# Example usage with Gradio for testing the heatmap generator
|
| 40 |
+
iface = gr.Interface(
|
| 41 |
+
fn=generate_heatmap,
|
| 42 |
+
inputs=gr.Textbox(label="Contract Text", placeholder="Enter the contract text here..."),
|
| 43 |
+
outputs=gr.HTML(),
|
| 44 |
+
title="Contract Risk Heatmap Generator",
|
| 45 |
+
description="Upload a contract and get a clause-level risk heatmap."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
iface.launch()
|