Raghu commited on
Commit
90f6477
·
1 Parent(s): 6ff2d52

Deploy dark UI + per-section feedback + schema guards

Browse files
Files changed (1) hide show
  1. app.py +35 -31
app.py CHANGED
@@ -69,6 +69,37 @@ def to_jsonable(obj):
69
  return None # avoid serializing images; skip in JSON
70
  return obj
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  # ============================================================================
73
  # Configuration
74
  # ============================================================================
@@ -942,36 +973,7 @@ with gr.Blocks(title="Receipt Processing Agent", theme=gr.themes.Soft(), css=CUS
942
  inputs=[input_image],
943
  outputs=[agent_summary, ocr_image_output, ocr_text_output, results_json, feedback_summary]
944
  )
945
-
946
-
947
- def save_feedback(assessment, notes, results_json_str, section="overall"):
948
- try:
949
- parsed = json.loads(results_json_str) if results_json_str else {}
950
- except Exception:
951
- parsed = {"raw": results_json_str}
952
- entry = {
953
- "timestamp": datetime.utcnow().isoformat(),
954
- "section": section or "",
955
- "assessment": assessment or "",
956
- "notes": notes or "",
957
- "results": parsed,
958
- }
959
- # Append to local CSV; safe for Spaces ephemeral storage
960
- import csv
961
- fieldnames = ["timestamp", "section", "assessment", "notes", "results"]
962
- file_exists = os.path.exists("feedback_logs.csv")
963
- with open("feedback_logs.csv", "a", newline="", encoding="utf-8") as f:
964
- writer = csv.DictWriter(f, fieldnames=fieldnames)
965
- if not file_exists:
966
- writer.writeheader()
967
- writer.writerow({
968
- "timestamp": entry["timestamp"],
969
- "section": entry.get("section", ""),
970
- "assessment": entry["assessment"],
971
- "notes": entry["notes"],
972
- "results": json.dumps(entry["results"]),
973
- })
974
- return "✅ Feedback saved. (Stored in feedback_logs.csv)"
975
 
976
  submit_feedback.click(
977
  fn=save_feedback,
@@ -987,6 +989,8 @@ if __name__ == "__main__":
987
  server_name="0.0.0.0",
988
  server_port=7860,
989
  show_error=True,
990
- show_api=False, # disable API schema generation to avoid json_schema crash
 
 
991
  )
992
 
 
69
  return None # avoid serializing images; skip in JSON
70
  return obj
71
 
72
+ # ---------------------------------------------------------------------------
73
+ # Feedback persistence helper (CSV; optionally include section label)
74
+ # ---------------------------------------------------------------------------
75
+ def save_feedback(assessment, notes, results_json_str, section="overall"):
76
+ try:
77
+ parsed = json.loads(results_json_str) if results_json_str else {}
78
+ except Exception:
79
+ parsed = {"raw": results_json_str}
80
+ entry = {
81
+ "timestamp": datetime.utcnow().isoformat(),
82
+ "section": section or "",
83
+ "assessment": assessment or "",
84
+ "notes": notes or "",
85
+ "results": parsed,
86
+ }
87
+ import csv
88
+ fieldnames = ["timestamp", "section", "assessment", "notes", "results"]
89
+ file_exists = os.path.exists("feedback_logs.csv")
90
+ with open("feedback_logs.csv", "a", newline="", encoding="utf-8") as f:
91
+ writer = csv.DictWriter(f, fieldnames=fieldnames)
92
+ if not file_exists:
93
+ writer.writeheader()
94
+ writer.writerow({
95
+ "timestamp": entry["timestamp"],
96
+ "section": entry.get("section", ""),
97
+ "assessment": entry["assessment"],
98
+ "notes": entry["notes"],
99
+ "results": json.dumps(entry["results"]),
100
+ })
101
+ return "✅ Feedback saved. (Stored in feedback_logs.csv)"
102
+
103
  # ============================================================================
104
  # Configuration
105
  # ============================================================================
 
973
  inputs=[input_image],
974
  outputs=[agent_summary, ocr_image_output, ocr_text_output, results_json, feedback_summary]
975
  )
976
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
977
 
978
  submit_feedback.click(
979
  fn=save_feedback,
 
989
  server_name="0.0.0.0",
990
  server_port=7860,
991
  show_error=True,
992
+ # keep API enabled; json_schema traversal is guarded by the gradio_client
993
+ # monkeypatch above (_safe_get_type / _safe_json_schema_to_python_type)
994
+ show_api=True,
995
  )
996