Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,90 +1,20 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
all_message.append({"role": "user", "content": message})
|
23 |
-
|
24 |
-
url = "https://api.together.xyz/v1/chat/completions"
|
25 |
-
payload = {
|
26 |
-
"model": "NousResearch/Nous-Hermes-2-Yi-34B",
|
27 |
-
"temperature": 1.05,
|
28 |
-
"top_p": 0.9,
|
29 |
-
"top_k": 50,
|
30 |
-
"repetition_penalty": 1,
|
31 |
-
"n": 1,
|
32 |
-
"messages": all_message,
|
33 |
-
"stream_tokens": True,
|
34 |
-
}
|
35 |
-
|
36 |
-
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
|
37 |
-
headers = {
|
38 |
-
"accept": "application/json",
|
39 |
-
"content-type": "application/json",
|
40 |
-
"Authorization": f"Bearer {TOGETHER_API_KEY}",
|
41 |
-
}
|
42 |
-
|
43 |
-
response = requests.post(url, json=payload, headers=headers, stream=True)
|
44 |
-
response.raise_for_status() # Ensure HTTP request was successful
|
45 |
-
|
46 |
-
for line in response.iter_lines():
|
47 |
-
if line:
|
48 |
-
decoded_line = line.decode('utf-8')
|
49 |
-
|
50 |
-
# Check for the completion signal
|
51 |
-
if decoded_line == "data: [DONE]":
|
52 |
-
return entire_assistant_response # Return the entire response at the end
|
53 |
-
|
54 |
-
try:
|
55 |
-
# Decode and strip any SSE format specific prefix ("data: ")
|
56 |
-
if decoded_line.startswith("data: "):
|
57 |
-
decoded_line = decoded_line.replace("data: ", "")
|
58 |
-
chunk_data = json.loads(decoded_line)
|
59 |
-
content = chunk_data['choices'][0]['delta']['content']
|
60 |
-
entire_assistant_response += content # Aggregate content
|
61 |
-
|
62 |
-
except json.JSONDecodeError:
|
63 |
-
print(f"Invalid JSON received: {decoded_line}")
|
64 |
-
continue
|
65 |
-
except KeyError as e:
|
66 |
-
print(f"KeyError encountered: {e}")
|
67 |
-
continue
|
68 |
-
|
69 |
-
return entire_assistant_response
|
70 |
-
|
71 |
-
# Streamlit application
|
72 |
-
st.sidebar.title("Raxder unofficial AI")
|
73 |
-
st.sidebar.write("This is NOT an AI Therapist, use it at your OWN RISK! This might be the worst AI you have ever used.")
|
74 |
-
|
75 |
-
history = []
|
76 |
-
if "history" not in st.session_state:
|
77 |
-
st.session_state.history = []
|
78 |
-
|
79 |
-
user_input = st.text_input("You:", key="user_input")
|
80 |
-
|
81 |
-
if st.button("Send"):
|
82 |
-
if user_input:
|
83 |
-
history = st.session_state.history
|
84 |
-
response = get_streamed_response(user_input, history)
|
85 |
-
history.append((user_input, response))
|
86 |
-
st.session_state.history = history
|
87 |
-
|
88 |
-
for human, assistant in st.session_state.history:
|
89 |
-
st.write(f"You: {human}")
|
90 |
-
st.write(f"notDave: {assistant}")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import time
|
3 |
+
import webbrowser
|
4 |
+
|
5 |
+
def redirect_to_website():
|
6 |
+
# Open the website in the default browser after a short delay
|
7 |
+
time.sleep(3) # Delay in seconds before redirecting
|
8 |
+
webbrowser.open_new_tab('https://ogegadavis254-roasting-2-0.hf.space')
|
9 |
+
return "Redirecting you to our new website..."
|
10 |
+
|
11 |
+
iface = gr.Interface(
|
12 |
+
fn=redirect_to_website,
|
13 |
+
title="Redirecting to Our New AI Experience",
|
14 |
+
description="You will be redirected to our new website shortly.",
|
15 |
+
theme="huggingface",
|
16 |
+
allow_flagging=False,
|
17 |
+
allow_screenshot=False
|
18 |
+
)
|
19 |
+
|
20 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|