Spaces:
Runtime error
Runtime error
DHRUV SHEKHAWAT commited on
Commit ·
9206c2d
1
Parent(s): a667f0a
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import streamlit as st
|
|
| 2 |
from streamlit_chat import message
|
| 3 |
import requests
|
| 4 |
|
| 5 |
-
url = 'https://
|
| 6 |
st.set_page_config(page_title="WebraftAI Chat", page_icon=":robot_face:")
|
| 7 |
st.markdown("<h1 style='text-align: center;'>WebraftAI Chat</h1>", unsafe_allow_html=True)
|
| 8 |
|
|
@@ -25,14 +25,14 @@ if 'api_key' not in st.session_state:
|
|
| 25 |
st.session_state['api_key']=""
|
| 26 |
|
| 27 |
st.sidebar.title("Settings")
|
| 28 |
-
model_name = st.sidebar.selectbox("Model:", ("gpt-3.5-turbo","gpt-3.5-turbo-16k","gpt-4-32k","claude-1","claude-2","palm-2","codellama-7b","llama2-7b","llama2-70b","openassistant-llama-30b","mini-orca-v3-13b"))
|
| 29 |
counter_placeholder = st.sidebar.empty()
|
| 30 |
|
| 31 |
api_key = st.sidebar.text_input("API_Key", value=st.session_state['api_key'], max_chars=None,placeholder=st.session_state['api_key'], key=None, type="password", label_visibility="visible")
|
| 32 |
st.session_state['api_key'] = api_key
|
| 33 |
max_tokens = st.sidebar.text_input("Max_tokens", value=4096, max_chars=None, key=None,placeholder=4096, type="default")
|
| 34 |
top_p = st.sidebar.text_input("Top_p", value=0.7, max_chars=None, key=None,placeholder=0.7, type="default")
|
| 35 |
-
temperature = st.sidebar.text_input("Temperature", value=0.
|
| 36 |
system_message = st.sidebar.text_area("System_message", value="You are a helpful AI assistant.", max_chars=None, key=None,placeholder="You are a helpful AI assistant.")
|
| 37 |
clear_button = st.sidebar.button("Clear Conversation", key="clear")
|
| 38 |
headers = {
|
|
@@ -48,7 +48,7 @@ if model_name == "gpt-3.5-turbo":
|
|
| 48 |
elif model_name == "gpt-3.5-turbo-16k":
|
| 49 |
model = "gpt-3.5-turbo-16k"
|
| 50 |
elif model_name == "gpt-4-32k":
|
| 51 |
-
model = "
|
| 52 |
elif model_name == "mini-orca-v3-13b":
|
| 53 |
model = "orca-mini-v3-13b"
|
| 54 |
else:
|
|
@@ -78,17 +78,52 @@ def evaluate(model, question, max_tokens=4096, top_p=0.7,temperature=0.1):
|
|
| 78 |
|
| 79 |
}
|
| 80 |
response = requests.post(url, headers=headers, json=data)
|
| 81 |
-
|
| 82 |
-
sentence = response['choices'][0]['message']['content']
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
return sentence
|
| 85 |
|
| 86 |
|
| 87 |
def generate_response(prompt):
|
| 88 |
st.session_state['messages'].append({"role": "user", "content": prompt})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
question = st.session_state['messages']
|
| 90 |
|
| 91 |
-
sentence = evaluate(model, question,top_p=float(top_p),max_tokens=
|
| 92 |
|
| 93 |
response = sentence
|
| 94 |
st.session_state['messages'].append({"role": "assistant", "content": response})
|
|
|
|
| 2 |
from streamlit_chat import message
|
| 3 |
import requests
|
| 4 |
|
| 5 |
+
url = 'https://paidapi-proxy003-webraftai.run-us-west2.goorm.app/v1/chat/completions'
|
| 6 |
st.set_page_config(page_title="WebraftAI Chat", page_icon=":robot_face:")
|
| 7 |
st.markdown("<h1 style='text-align: center;'>WebraftAI Chat</h1>", unsafe_allow_html=True)
|
| 8 |
|
|
|
|
| 25 |
st.session_state['api_key']=""
|
| 26 |
|
| 27 |
st.sidebar.title("Settings")
|
| 28 |
+
model_name = st.sidebar.selectbox("Model:", ("gpt-3.5-turbo","gpt-3.5-turbo-16k","gpt-4-32k","falcon-180b-chat","claude-1","claude-2","palm-2","codellama-7b","llama2-7b","llama2-70b","openassistant-llama-30b","mini-orca-v3-13b"))
|
| 29 |
counter_placeholder = st.sidebar.empty()
|
| 30 |
|
| 31 |
api_key = st.sidebar.text_input("API_Key", value=st.session_state['api_key'], max_chars=None,placeholder=st.session_state['api_key'], key=None, type="password", label_visibility="visible")
|
| 32 |
st.session_state['api_key'] = api_key
|
| 33 |
max_tokens = st.sidebar.text_input("Max_tokens", value=4096, max_chars=None, key=None,placeholder=4096, type="default")
|
| 34 |
top_p = st.sidebar.text_input("Top_p", value=0.7, max_chars=None, key=None,placeholder=0.7, type="default")
|
| 35 |
+
temperature = st.sidebar.text_input("Temperature", value=0.1, max_chars=None, key=None,placeholder=0.1, type="default")
|
| 36 |
system_message = st.sidebar.text_area("System_message", value="You are a helpful AI assistant.", max_chars=None, key=None,placeholder="You are a helpful AI assistant.")
|
| 37 |
clear_button = st.sidebar.button("Clear Conversation", key="clear")
|
| 38 |
headers = {
|
|
|
|
| 48 |
elif model_name == "gpt-3.5-turbo-16k":
|
| 49 |
model = "gpt-3.5-turbo-16k"
|
| 50 |
elif model_name == "gpt-4-32k":
|
| 51 |
+
model = "gpt-4-32k"
|
| 52 |
elif model_name == "mini-orca-v3-13b":
|
| 53 |
model = "orca-mini-v3-13b"
|
| 54 |
else:
|
|
|
|
| 78 |
|
| 79 |
}
|
| 80 |
response = requests.post(url, headers=headers, json=data)
|
| 81 |
+
try:
|
|
|
|
| 82 |
|
| 83 |
+
response = response.json()
|
| 84 |
+
|
| 85 |
+
sentence = response['choices'][0]['message']['content']
|
| 86 |
+
if sentence:
|
| 87 |
+
sentence = response['choices'][0]['message']['content']
|
| 88 |
+
else:
|
| 89 |
+
sentie = response
|
| 90 |
+
sentence = f"API Returned: ```{sentie}``` \n Is the API not working? check https://stats.uptimerobot.com/KkZE2T84mj \n If you are still encountering errors then please open a ticket from our discord server at https://discord.gg/webraftai . "
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
except requests.exceptions.JSONDecodeError as e:
|
| 94 |
+
sentie= response.content
|
| 95 |
+
sentence = f"API Returned: ```{sentie}``` \n Is the API not working? check https://stats.uptimerobot.com/KkZE2T84mj \n If you are still encountering errors then please open a ticket from our discord server at https://discord.gg/webraftai . "
|
| 96 |
return sentence
|
| 97 |
|
| 98 |
|
| 99 |
def generate_response(prompt):
|
| 100 |
st.session_state['messages'].append({"role": "user", "content": prompt})
|
| 101 |
+
if prompt.startswith("draw"):
|
| 102 |
+
data = {"prompt": prompt,
|
| 103 |
+
"model": "realistic-vision-v1-4"
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
response = requests.post("https://api.webraft.in/api/images/generations", json=data, headers=headers)
|
| 107 |
+
total_tokens = "153"
|
| 108 |
+
prompt_tokens = "153"
|
| 109 |
+
completion_tokens = "153"
|
| 110 |
+
try:
|
| 111 |
+
|
| 112 |
+
response = response.json()
|
| 113 |
+
imageurl = response['data'][0]['url']
|
| 114 |
+
ie = f"Here is the generated image: {imageurl} \n Model used: `realistic-vision-v1-4`"
|
| 115 |
+
st.session_state['messages'].append({"role": "assistant", "content": ie})
|
| 116 |
+
|
| 117 |
+
except requests.exceptions.JSONDecodeError as e:
|
| 118 |
+
sentie = response.content
|
| 119 |
+
ie= f"Image generation API returned: ```{sentie}``` \n Is the API not working? check https://stats.uptimerobot.com/KkZE2T84mj \n If you are still encountering errors then please open a ticket from our discord server at https://discord.gg/webraftai . "
|
| 120 |
+
st.session_state['messages'].append({"role": "assistant", "content": ie})
|
| 121 |
+
return ie,total_tokens,prompt_tokens,completion_tokens
|
| 122 |
+
|
| 123 |
+
|
| 124 |
question = st.session_state['messages']
|
| 125 |
|
| 126 |
+
sentence = evaluate(model, question,top_p=float(top_p),max_tokens=int(max_tokens),temperature=float(temperature))
|
| 127 |
|
| 128 |
response = sentence
|
| 129 |
st.session_state['messages'].append({"role": "assistant", "content": response})
|