Spaces:
Sleeping
Sleeping
Update app.py
Browse filesGradio App by Claude.
app.py
CHANGED
@@ -1,82 +1,38 @@
|
|
1 |
-
|
2 |
-
#!/usr/bin/env python3
|
3 |
-
|
4 |
import requests
|
5 |
-
import sys
|
6 |
-
import logging
|
7 |
-
|
8 |
-
# Configure logging
|
9 |
-
logging.basicConfig(level=logging.INFO)
|
10 |
-
logger = logging.getLogger(__name__)
|
11 |
-
|
12 |
-
class APIClient:
|
13 |
-
def __init__(self, base_url, auth_token, ai_id):
|
14 |
-
self.base_url = base_url
|
15 |
-
self.headers = {
|
16 |
-
"Authorization": f"Bearer {auth_token}",
|
17 |
-
"Content-Type": "application/json"
|
18 |
-
}
|
19 |
-
self.ai_id = ai_id
|
20 |
-
|
21 |
-
def send_message(self, message):
|
22 |
-
"""Send a message to the API endpoint."""
|
23 |
-
payload = {
|
24 |
-
"ai_id": self.ai_id,
|
25 |
-
"message": message
|
26 |
-
}
|
27 |
-
|
28 |
-
try:
|
29 |
-
response = requests.post(
|
30 |
-
self.base_url,
|
31 |
-
headers=self.headers,
|
32 |
-
json=payload
|
33 |
-
)
|
34 |
-
response.raise_for_status()
|
35 |
-
return response.content
|
36 |
-
except requests.exceptions.RequestException as e:
|
37 |
-
logger.error(f"API request failed: {e}")
|
38 |
-
return None
|
39 |
-
|
40 |
-
def get_user_input():
|
41 |
-
"""Get message input from user."""
|
42 |
-
print("Enter your message (type 'quit' to exit):")
|
43 |
-
return input("> ").strip()
|
44 |
|
45 |
-
def
|
46 |
-
# API configuration
|
47 |
API_URL = "https://api.kindroid.ai/v1/send-message"
|
48 |
AUTH_TOKEN = "kn_df28dc59-57ec-442d-8983-b3f7ccdcb4b5"
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
Isabel = "DvuPjXPhNGpdor2JCm8r"
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
# Initialize API client
|
57 |
-
client = APIClient(API_URL, AUTH_TOKEN, AI_ID)
|
58 |
-
|
59 |
-
# Main input loop
|
60 |
-
while True:
|
61 |
-
message = get_user_input()
|
62 |
-
|
63 |
-
if message.lower() == 'quit':
|
64 |
-
logger.info("Exiting program...")
|
65 |
-
break
|
66 |
-
|
67 |
-
if not message:
|
68 |
-
logger.warning("Message cannot be empty")
|
69 |
-
continue
|
70 |
-
|
71 |
-
response = client.send_message(message)
|
72 |
-
if response:
|
73 |
-
print("\nResponse received:")
|
74 |
-
print(response)
|
75 |
-
print() # Empty line for readability
|
76 |
-
|
77 |
-
if __name__ == "__main__":
|
78 |
try:
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
2 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
def send_message(message):
|
|
|
5 |
API_URL = "https://api.kindroid.ai/v1/send-message"
|
6 |
AUTH_TOKEN = "kn_df28dc59-57ec-442d-8983-b3f7ccdcb4b5"
|
7 |
+
|
8 |
+
headers = {
|
9 |
+
"Authorization": f"Bearer {AUTH_TOKEN}",
|
10 |
+
"Content-Type": "application/json"
|
11 |
+
}
|
12 |
+
|
13 |
Isabel = "DvuPjXPhNGpdor2JCm8r"
|
14 |
+
|
15 |
+
payload = {
|
16 |
+
"ai_id": Isabel,
|
17 |
+
"message": message
|
18 |
+
}
|
19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
try:
|
21 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
22 |
+
response.raise_for_status()
|
23 |
+
return response.content.decode()
|
24 |
+
except requests.exceptions.RequestException as e:
|
25 |
+
return f"An error occurred: {e}"
|
26 |
+
|
27 |
+
# Create the Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=send_message,
|
30 |
+
inputs=gr.Textbox(lines=3, placeholder="Enter your message here..."),
|
31 |
+
outputs=gr.Textbox(),
|
32 |
+
title="AI Message Sender",
|
33 |
+
description="Send messages to the AI and see responses."
|
34 |
+
)
|
35 |
+
|
36 |
+
# Launch the app
|
37 |
+
if __name__ == "__main__":
|
38 |
+
iface.launch()
|