File size: 1,070 Bytes
317fa89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
import json

DEBUG_MODE = False

def echo(text, request: gr.Request):
    output_text = {"report1": "SUCCESS"}  # Initialize as a dictionary
    output_text["report2"] = "You inserted the text:" 
    output_text["report3"] = text
    if request:
        if DEBUG_MODE:
            print("Request object:", request)
            print("Request headers dictionary:", request.headers)
            print("IP address:", request.client.host)
            print("Query parameters:", dict(request.query_params))
        # Convert headers to a dictionary and include them in the output_text
        output_text["headers"] = dict(request.headers.items())
        output_text["host"] = request.client.host
        output_text["query_params"] = dict(request.query_params)
    if DEBUG_MODE:
        print("Query parameters:", dict(request.query_params))
    
    # Convert the output_text dictionary to a JSON-formatted string
    output_text_json = json.dumps(output_text)
    return output_text_json

io = gr.Interface(echo, "textbox", "json").launch(share=True)