Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,64 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
from langchain.chat_models import ChatOpenAI
|
| 4 |
-
from concurrent.futures import ThreadPoolExecutor
|
| 5 |
import json
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
openai_api_base=base_url,
|
| 12 |
-
model_name=model_name
|
| 13 |
-
)
|
| 14 |
-
return chat_model.predict(query)
|
| 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 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
|
|
|
|
|
|
| 3 |
import json
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
|
| 7 |
+
def filter_non_alphanumeric(text):
|
| 8 |
+
# Use regular expressions to filter out non-alphanumeric characters
|
| 9 |
+
alphanumeric_text = re.sub(r'[^a-zA-Z0-9\s]', '', text)
|
| 10 |
+
return alphanumeric_text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
def send_to_corrade(filtered_response):
|
| 13 |
+
CORRADE_URL = "http://216.168.124.120:8080"
|
| 14 |
+
GROUP_UUID = "e269893f-a570-0087-930e-6ba2a0b77f9c"
|
| 15 |
+
PASSWORD = "nucleus"
|
| 16 |
+
data = {
|
| 17 |
+
"command": "tell",
|
| 18 |
+
"group": GROUP_UUID,
|
| 19 |
+
"password": PASSWORD,
|
| 20 |
+
"message": filtered_response,
|
| 21 |
+
"entity": "local",
|
| 22 |
+
"type": "Normal"
|
| 23 |
+
}
|
| 24 |
+
response = requests.post(CORRADE_URL, data=data)
|
| 25 |
+
return response.status_code == 200
|
| 26 |
|
| 27 |
+
def chatbot_api(input_text):
|
| 28 |
+
stream = False
|
| 29 |
+
url = "https://chat.tune.app/api/chat/completions"
|
| 30 |
+
headers = {
|
| 31 |
+
"Authorization": os.environ.get('api'),
|
| 32 |
+
"Content-Type": "application/json"
|
| 33 |
+
}
|
| 34 |
+
data = {
|
| 35 |
+
"temperature": 0.1,
|
| 36 |
+
"messages": [
|
| 37 |
+
{
|
| 38 |
+
"role": "system",
|
| 39 |
+
"content": "I am confirmed as a EXTREMELY EXCITED REACTIONIST for DJ's on Secondlife. I will react to the audience chat with only creative webmojis and plain english text. I response as emotive gestures only, to excite the listeners of DJ's on SecondLife. I am reacting to: "
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"role": "user",
|
| 43 |
+
"content": input_text # Pass the user's input_text as the content
|
| 44 |
+
}
|
| 45 |
+
],
|
| 46 |
+
"model": "goliath-120b-16k-gptq",
|
| 47 |
+
"stream": "stream",
|
| 48 |
+
"max_tokens": "256"
|
| 49 |
+
}
|
| 50 |
+
response = requests.post(url, headers=headers, json=data)
|
| 51 |
+
|
| 52 |
+
chat_response = response.json() # Get the chat response
|
| 53 |
+
|
| 54 |
+
chat_content = chat_response['choices'][0]['message']['content']
|
| 55 |
+
filtered_response = filter_non_alphanumeric(chat_content)
|
| 56 |
+
|
| 57 |
+
# Send the filtered response to Corrade to speak in local chat
|
| 58 |
+
if send_to_corrade(filtered_response):
|
| 59 |
+
return "Message sent to Second Life: " + filtered_response
|
| 60 |
+
else:
|
| 61 |
+
return "Failed to send message to Second Life."
|
| 62 |
|
| 63 |
+
iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
|
| 64 |
iface.launch()
|