Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
def interact_with_server(prompt
|
| 5 |
server_url = "http://xzyorb.servemp3.com:80"
|
| 6 |
response = requests.post(server_url, data={"prompt": prompt})
|
| 7 |
response_text = response.text
|
| 8 |
|
| 9 |
# Count the number of messages in the conversation
|
| 10 |
-
conversation_messages = response_text.split("
|
| 11 |
num_messages = len(conversation_messages)
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
print("IP Address:", ip_address)
|
| 15 |
print("User Agent:", user_agent)
|
| 16 |
print("Number of Messages:", num_messages)
|
| 17 |
-
|
| 18 |
-
return response_text
|
| 19 |
|
| 20 |
iface = gr.Interface(
|
| 21 |
fn=interact_with_server,
|
| 22 |
-
inputs=
|
| 23 |
-
outputs=gr.outputs.HTML()
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
+
def interact_with_server(prompt):
|
| 5 |
server_url = "http://xzyorb.servemp3.com:80"
|
| 6 |
response = requests.post(server_url, data={"prompt": prompt})
|
| 7 |
response_text = response.text
|
| 8 |
|
| 9 |
# Count the number of messages in the conversation
|
| 10 |
+
conversation_messages = response_text.split("<br>") # Assuming each message is separated by "<br>"
|
| 11 |
num_messages = len(conversation_messages)
|
| 12 |
|
| 13 |
+
return response_text, num_messages
|
| 14 |
+
|
| 15 |
+
def print_session_data(data):
|
| 16 |
+
response_text, num_messages = data
|
| 17 |
+
session = gr.capture_session()
|
| 18 |
+
ip_address = session["ip"]
|
| 19 |
+
user_agent = session["user_agent"]
|
| 20 |
+
|
| 21 |
print("IP Address:", ip_address)
|
| 22 |
print("User Agent:", user_agent)
|
| 23 |
print("Number of Messages:", num_messages)
|
|
|
|
|
|
|
| 24 |
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=interact_with_server,
|
| 27 |
+
inputs=gr.inputs.Textbox(),
|
| 28 |
+
outputs=[gr.outputs.HTML(), gr.outputs.Number()], # Return both response text and number of messages
|
| 29 |
+
capture_session=True # Automatically captures IP address and user agent
|
| 30 |
)
|
| 31 |
|
| 32 |
+
iface.launch(print_session_data) # Pass the function to print session data to the launch method
|