Spaces:
Paused
Paused
File size: 1,024 Bytes
520af46 88be9f7 520af46 88be9f7 520af46 88be9f7 520af46 88be9f7 520af46 |
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 28 29 30 31 32 |
import time, requests
ENDPOINT = "https://pawinc-chadalpaca-flask.hf.space/chat"
serverIsPreparing = True
print("Checking server status")
while serverIsPreparing:
try:
with requests.get(ENDPOINT) as r:
print("Status Check: " + r.text)
if r.text == 'Ready':
break
else:
time.sleep(5)
except requests.exceptions.ConnectionError:
print("Connection Refused. Retrying in 5 seconds.")
time.sleep(5)
print("Server is ready. Starting client.")
headers = {"Content-type": "application/json", "Authorization": "test:test"}
messages = [
{"role": "user", "content": "Hello, how are you feeling today?"},
{"role": "assistant", "content": "I'm feeling great. How about you?"},
{"role": "user", "content": "I'm fine, thanks for asking."}
]
print("Sending Request...")
try:
with requests.post(ENDPOINT, headers=headers, json=messages) as r:
print(r.json()["content"])
except requests.exceptions.JSONDecodeError:
print(f"Something went wrong: {r.status_code}- {r.text}") |