Spaces:
Runtime error
Runtime error
no message
Browse files- app_old2.py +27 -0
app_old2.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
DEBUG_MODE = False
|
| 5 |
+
|
| 6 |
+
def echo(text, request: gr.Request):
|
| 7 |
+
output_text = {"report1": "SUCCESS"} # Initialize as a dictionary
|
| 8 |
+
output_text["report2"] = "You inserted the text:"
|
| 9 |
+
output_text["report3"] = text
|
| 10 |
+
if request:
|
| 11 |
+
if DEBUG_MODE:
|
| 12 |
+
print("Request object:", request)
|
| 13 |
+
print("Request headers dictionary:", request.headers)
|
| 14 |
+
print("IP address:", request.client.host)
|
| 15 |
+
print("Query parameters:", dict(request.query_params))
|
| 16 |
+
# Convert headers to a dictionary and include them in the output_text
|
| 17 |
+
output_text["headers"] = dict(request.headers.items())
|
| 18 |
+
output_text["host"] = request.client.host
|
| 19 |
+
output_text["query_params"] = dict(request.query_params)
|
| 20 |
+
if DEBUG_MODE:
|
| 21 |
+
print("Query parameters:", dict(request.query_params))
|
| 22 |
+
|
| 23 |
+
# Convert the output_text dictionary to a JSON-formatted string
|
| 24 |
+
output_text_json = json.dumps(output_text)
|
| 25 |
+
return output_text_json
|
| 26 |
+
|
| 27 |
+
io = gr.Interface(echo, "textbox", "json").launch(share=True)
|