ramagururadhakrishnan commited on
Commit
df40255
·
verified ·
1 Parent(s): d629c53
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -92,7 +92,6 @@ def plot_graph(B, user_risk):
92
  font_size=10, width=[B[u][v]['weight'] for u, v in B.edges()])
93
  plt.title("User-Word Bipartite Graph with Risk Heatmap")
94
 
95
- # Capture figure before closing
96
  fig_canvas = fig
97
  plt.close(fig) # release memory
98
  return fig_canvas
@@ -106,6 +105,10 @@ def analyze_chat(file):
106
  Processes entirely in memory to avoid storage issues.
107
  """
108
  try:
 
 
 
 
109
  raw_bytes = file.read()
110
  if file.name.endswith(".csv"):
111
  df = pd.read_csv(BytesIO(raw_bytes))
@@ -138,7 +141,7 @@ def analyze_chat(file):
138
  # -------------------------------
139
  iface = gr.Interface(
140
  fn=analyze_chat,
141
- inputs=gr.File(label="Upload Chat CSV/JSON", file_types=['.csv', '.json'], type='file', max_size=10_000_000),
142
  outputs=[gr.Textbox(label="Metrics"), gr.Plot(label="Risk Graph")],
143
  title="Sex Chat Detection",
144
  description="Upload a chat file (CSV or JSON) to detect sex chat, compute metrics, and visualize the user-word graph."
 
92
  font_size=10, width=[B[u][v]['weight'] for u, v in B.edges()])
93
  plt.title("User-Word Bipartite Graph with Risk Heatmap")
94
 
 
95
  fig_canvas = fig
96
  plt.close(fig) # release memory
97
  return fig_canvas
 
105
  Processes entirely in memory to avoid storage issues.
106
  """
107
  try:
108
+ # Manual file size check (10 MB max)
109
+ if file.size > 10_000_000:
110
+ return "File too large. Max size is 10 MB.", None
111
+
112
  raw_bytes = file.read()
113
  if file.name.endswith(".csv"):
114
  df = pd.read_csv(BytesIO(raw_bytes))
 
141
  # -------------------------------
142
  iface = gr.Interface(
143
  fn=analyze_chat,
144
+ inputs=gr.File(label="Upload Chat CSV/JSON", file_types=['.csv', '.json'], type='file'),
145
  outputs=[gr.Textbox(label="Metrics"), gr.Plot(label="Risk Graph")],
146
  title="Sex Chat Detection",
147
  description="Upload a chat file (CSV or JSON) to detect sex chat, compute metrics, and visualize the user-word graph."