Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -110,6 +110,35 @@ def test_agent_availability(agent_url):
|
|
110 |
except requests.exceptions.RequestException as e:
|
111 |
return f"β Agent not available: {str(e)}", {"error": str(e)}
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# Gradio UI with improved layout
|
114 |
with gr.Blocks(title="OpenFloor Protocol Tester", theme=gr.themes.Soft()) as demo:
|
115 |
gr.Markdown("""
|
@@ -155,27 +184,13 @@ with gr.Blocks(title="OpenFloor Protocol Tester", theme=gr.themes.Soft()) as dem
|
|
155 |
|
156 |
# Right Column - Results
|
157 |
with gr.Column(scale=3):
|
158 |
-
gr.Markdown("### π Assistant Status")
|
159 |
-
|
160 |
-
with gr.Row():
|
161 |
-
availability_status = gr.Textbox(
|
162 |
-
label="Connection Status",
|
163 |
-
interactive=False,
|
164 |
-
container=False
|
165 |
-
)
|
166 |
-
|
167 |
-
availability_response = gr.JSON(
|
168 |
-
label="Availability Response",
|
169 |
-
container=False
|
170 |
-
)
|
171 |
-
|
172 |
gr.Markdown("### π‘ Request & Response")
|
173 |
|
174 |
-
# Status message for
|
175 |
request_status = gr.Textbox(
|
176 |
-
label="
|
177 |
interactive=False,
|
178 |
-
|
179 |
)
|
180 |
|
181 |
# Collapsible request details
|
@@ -188,7 +203,7 @@ with gr.Blocks(title="OpenFloor Protocol Tester", theme=gr.themes.Soft()) as dem
|
|
188 |
|
189 |
# Response section
|
190 |
with gr.Group():
|
191 |
-
gr.Markdown("#### π₯
|
192 |
|
193 |
with gr.Row():
|
194 |
status_code = gr.Number(
|
@@ -205,19 +220,19 @@ with gr.Blocks(title="OpenFloor Protocol Tester", theme=gr.themes.Soft()) as dem
|
|
205 |
|
206 |
# Event handlers
|
207 |
test_btn.click(
|
208 |
-
fn=
|
209 |
inputs=[agent_url],
|
210 |
-
outputs=[
|
211 |
)
|
212 |
|
213 |
def handle_send_request(*args):
|
214 |
envelope, status, response, status_msg = send_request(*args)
|
215 |
-
return envelope, status, response, status_msg
|
216 |
|
217 |
send_btn.click(
|
218 |
fn=handle_send_request,
|
219 |
inputs=[agent_url, request_type, message_text],
|
220 |
-
outputs=[envelope_output, status_code, response_output, request_status
|
221 |
)
|
222 |
|
223 |
gr.Markdown("""
|
|
|
110 |
except requests.exceptions.RequestException as e:
|
111 |
return f"β Agent not available: {str(e)}", {"error": str(e)}
|
112 |
|
113 |
+
# Enhanced test function that also shows the envelope
|
114 |
+
def test_agent_with_envelope(agent_url):
|
115 |
+
try:
|
116 |
+
# Send a simple manifest request to test
|
117 |
+
envelope = build_manifest_request_envelope(agent_url)
|
118 |
+
json_str = envelope.to_json()
|
119 |
+
envelope_dict = json.loads(json_str)
|
120 |
+
json_payload_pretty = json.dumps({"openFloor": envelope_dict}, indent=2)
|
121 |
+
payload = {"openFloor": envelope_dict}
|
122 |
+
|
123 |
+
headers = {'Content-Type': 'application/json'}
|
124 |
+
response = requests.post(agent_url, json=payload, headers=headers, timeout=5)
|
125 |
+
|
126 |
+
if response.status_code == 200:
|
127 |
+
try:
|
128 |
+
response_json = response.json()
|
129 |
+
status_msg = f"β
Agent available at {agent_url}"
|
130 |
+
return status_msg, response_json, json_payload_pretty, response.status_code
|
131 |
+
except:
|
132 |
+
status_msg = f"β
Agent responded but with non-JSON"
|
133 |
+
return status_msg, {"raw_response": response.text}, json_payload_pretty, response.status_code
|
134 |
+
else:
|
135 |
+
status_msg = f"β οΈ Agent responded with status {response.status_code}"
|
136 |
+
return status_msg, {"status": response.status_code, "response": response.text}, json_payload_pretty, response.status_code
|
137 |
+
|
138 |
+
except requests.exceptions.RequestException as e:
|
139 |
+
status_msg = f"β Agent not available: {str(e)}"
|
140 |
+
return status_msg, {"error": str(e)}, "", 0
|
141 |
+
|
142 |
# Gradio UI with improved layout
|
143 |
with gr.Blocks(title="OpenFloor Protocol Tester", theme=gr.themes.Soft()) as demo:
|
144 |
gr.Markdown("""
|
|
|
184 |
|
185 |
# Right Column - Results
|
186 |
with gr.Column(scale=3):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
gr.Markdown("### π‘ Request & Response")
|
188 |
|
189 |
+
# Status message for all requests
|
190 |
request_status = gr.Textbox(
|
191 |
+
label="Status",
|
192 |
interactive=False,
|
193 |
+
container=False
|
194 |
)
|
195 |
|
196 |
# Collapsible request details
|
|
|
203 |
|
204 |
# Response section
|
205 |
with gr.Group():
|
206 |
+
gr.Markdown("#### π₯ Response")
|
207 |
|
208 |
with gr.Row():
|
209 |
status_code = gr.Number(
|
|
|
220 |
|
221 |
# Event handlers
|
222 |
test_btn.click(
|
223 |
+
fn=test_agent_with_envelope,
|
224 |
inputs=[agent_url],
|
225 |
+
outputs=[request_status, response_output, envelope_output, status_code]
|
226 |
)
|
227 |
|
228 |
def handle_send_request(*args):
|
229 |
envelope, status, response, status_msg = send_request(*args)
|
230 |
+
return envelope, status, response, status_msg
|
231 |
|
232 |
send_btn.click(
|
233 |
fn=handle_send_request,
|
234 |
inputs=[agent_url, request_type, message_text],
|
235 |
+
outputs=[envelope_output, status_code, response_output, request_status]
|
236 |
)
|
237 |
|
238 |
gr.Markdown("""
|