Spaces:
Sleeping
Sleeping
File size: 1,634 Bytes
5fa7d9f |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import requests
import json
def send_message(message):
# Define the API endpoint URL
url = 'https://severian-anything.hf.space/api/v1/workspace/Scoreboard/chat'
# Define the request headers
headers = {
'accept': 'application/json',
'Authorization': 'Bearer TYQYM46-RPCMQ98-GCGJMNB-Q23K6HC',
'Content-Type': 'application/json'
}
# Define the request body for the new message
data = {
"message": message,
"mode": "query"
}
# Convert the data dictionary to JSON format
data_json = json.dumps(data)
try:
# Send the POST request
response = requests.post(url, headers=headers, data=data_json)
# Parse the response JSON data
response_data = response.json()
# Get the bot's response
bot_response = response_data.get("textResponse")
# Print the bot's response
if bot_response:
print(f"Bot: {bot_response}")
# Prompt for a new message
new_message = input("You: ")
# Return the new message
return new_message
except requests.RequestException as e:
print(f"Request failed: {e}")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
if __name__ == "__main__":
# Initial message
message = input("You: ")
while message.lower() != "exit":
# Send the user's message and get a new message
message = send_message(message)
print("Chat ended.")
|