tlogandesigns commited on
Commit
8ef4148
·
1 Parent(s): 27b36ba

styled output

Browse files
Files changed (1) hide show
  1. app.py +50 -6
app.py CHANGED
@@ -74,12 +74,56 @@ with gr.Blocks(title="Image + Text Compliance Check") as demo:
74
  hf_repo = gr.Textbox(label="HF repo", value=DEFAULT_HF_REPO)
75
  hf_thresh = gr.Slider(label="ML threshold", minimum=0.5, maximum=0.99, step=0.01, value=float(DEFAULT_HF_THRESH))
76
 
77
- out = gr.Code(label="Result JSON", language="json")
78
- gr.Button("Run Compliance Check").click(
79
- fn=on_run,
80
- inputs=[image, ptxt, social, agent_name, agent_phone, company_name, company_phones_json, disclaimer,
81
- enable_ml, hf_repo, hf_thresh],
82
- outputs=[out],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  )
84
 
85
  if __name__ == "__main__":
 
74
  hf_repo = gr.Textbox(label="HF repo", value=DEFAULT_HF_REPO)
75
  hf_thresh = gr.Slider(label="ML threshold", minimum=0.5, maximum=0.99, step=0.01, value=float(DEFAULT_HF_THRESH))
76
 
77
+ out = gr.Code(label="Result JSON", language="json", visible=False)
78
+
79
+ with gr.Row():
80
+ gr.Button("Run Compliance Check").click(
81
+ fn=on_run,
82
+ inputs=[image, ptxt, social, agent_name, agent_phone, company_name, company_phones_json, disclaimer,
83
+ enable_ml, hf_repo, hf_thresh],
84
+ outputs=[out],
85
+ )
86
+
87
+ with gr.Row():
88
+ fair_housing_out = gr.Textbox(label="Fair Housing", interactive=False)
89
+ ptxt_out = gr.Textbox(label="Post Text", interactive=False)
90
+ img_out = gr.Textbox(label="Image Text", interactive=False)
91
+
92
+ def update_results(results_json):
93
+ results = json.loads(results_json)
94
+
95
+ fh_compliant = results.get("Fair_Housing", {}).get("compliant", False)
96
+ ptxt_compliant = results.get("Ptxt", {}).get("compliant", False)
97
+ img_compliant = results.get("img", {}).get("compliant", False)
98
+
99
+ return {
100
+ fair_housing_out: gr.update(
101
+ value="Compliant" if fh_compliant else "Not Compliant",
102
+ style={
103
+ "background-color": "green" if fh_compliant else "red",
104
+ "color": "white",
105
+ }
106
+ ),
107
+ ptxt_out: gr.update(
108
+ value="Compliant" if ptxt_compliant else "Not Compliant",
109
+ style={
110
+ "background-color": "green" if ptxt_compliant else "red",
111
+ "color": "white",
112
+ }
113
+ ),
114
+ img_out: gr.update(
115
+ value="Compliant" if img_compliant else "Not Compliant",
116
+ style={
117
+ "background-color": "green" if img_compliant else "red",
118
+ "color": "white",
119
+ }
120
+ )
121
+ }
122
+
123
+ out.change(
124
+ fn=update_results,
125
+ inputs=[out],
126
+ outputs=[fair_housing_out, ptxt_out, img_out]
127
  )
128
 
129
  if __name__ == "__main__":