Spaces:
Sleeping
Sleeping
Update app.py
Browse filesSwitch to different working code. Need to integrate with Gradio.
app.py
CHANGED
@@ -1,41 +1,82 @@
|
|
1 |
# Import the requests library - this is the standard library for making HTTP requests in Python
|
|
|
|
|
2 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
# Content-Type is set to application/json since we're sending JSON data
|
11 |
-
headers = {
|
12 |
-
"Authorization": f"Bearer {AUTH_TOKEN}",
|
13 |
-
"Content-Type": "application/json"
|
14 |
-
}
|
15 |
-
|
16 |
-
Isabel = "DvuPjXPhNGpdor2JCm8r"
|
17 |
-
|
18 |
-
# Prepare the data we want to send
|
19 |
-
# This follows the required format with ai_id and message fields
|
20 |
-
payload = {
|
21 |
-
"ai_id": Isabel,
|
22 |
-
"message": "Oh god izz that feels good. keep going."
|
23 |
-
}
|
24 |
-
|
25 |
-
try:
|
26 |
-
# Make the POST request to the API
|
27 |
-
# We pass our payload as json parameter so requests will automatically
|
28 |
-
# handle the JSON serialization for us
|
29 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
30 |
-
|
31 |
-
# Check if the request was successful (status code 200-299)
|
32 |
-
response.raise_for_status()
|
33 |
-
|
34 |
-
# Print the response from the server
|
35 |
-
# The .json() method automatically parses the JSON response
|
36 |
-
print("Response received:")
|
37 |
-
print(response.content)
|
38 |
-
|
39 |
-
except requests.exceptions.RequestException as e:
|
40 |
-
# Handle any errors that might occur during the request
|
41 |
-
print(f"An error occurred: {e}")
|
|
|
1 |
# Import the requests library - this is the standard library for making HTTP requests in Python
|
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 main():
|
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 |
+
Stacy = "iLM2yh7p8yltOjaLkoZF"
|
51 |
+
Tina = "OD4KbJbY19cM2uiikVMy"
|
52 |
+
Amanda = "UzkaaTD6l1Pdfk4Htcmu"
|
53 |
+
Dude = "itlcKws8t1JFXZRLte8W"
|
54 |
+
AI_ID = Isabel
|
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 |
+
main()
|
80 |
+
except KeyboardInterrupt:
|
81 |
+
logger.info("\nProgram terminated by user")
|
82 |
+
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|