Spaces:
Running
Running
Merge branch 'beta_feature/return_json' into develop
Browse files- app.py +19 -5
- flagged/log.csv +4 -0
app.py
CHANGED
@@ -1,11 +1,25 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
def echo(text, request: gr.Request):
|
|
|
4 |
if request:
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
print("Query parameters:", dict(request.query_params))
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
11 |
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
+
|
4 |
+
DEBUG_MODE = True
|
5 |
|
6 |
def echo(text, request: gr.Request):
|
7 |
+
output_text = {"text": text} # Initialize as a dictionary
|
8 |
if request:
|
9 |
+
if DEBUG_MODE:
|
10 |
+
print("Request object:", request)
|
11 |
+
print("Request headers dictionary:", request.headers)
|
12 |
+
print("IP address:", request.client.host)
|
13 |
+
print("Query parameters:", dict(request.query_params))
|
14 |
+
# Convert headers to a dictionary and include them in the output_text
|
15 |
+
output_text["headers"] = dict(request.headers.items())
|
16 |
+
output_text["host"] = request.client.host
|
17 |
+
output_text["query_params"] = dict(request.query_params)
|
18 |
+
if DEBUG_MODE:
|
19 |
print("Query parameters:", dict(request.query_params))
|
20 |
+
|
21 |
+
# Convert the output_text dictionary to a JSON-formatted string
|
22 |
+
output_text_json = json.dumps(output_text)
|
23 |
+
return output_text_json
|
24 |
|
25 |
+
io = gr.Interface(echo, "textbox", "json").launch(share=True)
|
flagged/log.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
text,output,flag,username,timestamp
|
2 |
+
asas,,,,2024-03-08 11:14:29.724973
|
3 |
+
asas,,,,2024-03-08 11:14:32.403973
|
4 |
+
zcvxc,,,,2024-03-08 11:27:37.358751
|