Streamlit conversion
Browse files
app.py
CHANGED
@@ -1,9 +1,13 @@
|
|
1 |
-
import
|
2 |
from openai import OpenAI, APIError
|
3 |
import os
|
4 |
import tenacity
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
7 |
|
8 |
client = OpenAI(
|
9 |
base_url="https://api-inference.huggingface.co/v1/",
|
@@ -33,7 +37,7 @@ def respond(
|
|
33 |
response = ""
|
34 |
|
35 |
for message in client.chat.completions.create(
|
36 |
-
model=
|
37 |
max_tokens=max_tokens,
|
38 |
stream=True,
|
39 |
temperature=temperature,
|
@@ -62,25 +66,16 @@ def respond(
|
|
62 |
print(f"Error: {e}")
|
63 |
yield "Error occurred. Please try again."
|
64 |
|
65 |
-
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
step=0.05,
|
78 |
-
label="Top-P",
|
79 |
-
),
|
80 |
-
|
81 |
-
],
|
82 |
-
fill_height=True,
|
83 |
-
chatbot=chatbot
|
84 |
-
)
|
85 |
-
if __name__ == "__main__":
|
86 |
-
demo.launch(show_error=True)
|
|
|
1 |
+
import streamlit as st
|
2 |
from openai import OpenAI, APIError
|
3 |
import os
|
4 |
import tenacity
|
5 |
|
6 |
+
# Get the OpenAI API key from the Space settings
|
7 |
+
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
|
8 |
+
|
9 |
+
# Get the model name from the Space settings
|
10 |
+
MODEL = "NousResearch/Hermes-3-Llama-3.1-8B"
|
11 |
|
12 |
client = OpenAI(
|
13 |
base_url="https://api-inference.huggingface.co/v1/",
|
|
|
37 |
response = ""
|
38 |
|
39 |
for message in client.chat.completions.create(
|
40 |
+
model=MODEL,
|
41 |
max_tokens=max_tokens,
|
42 |
stream=True,
|
43 |
temperature=temperature,
|
|
|
66 |
print(f"Error: {e}")
|
67 |
yield "Error occurred. Please try again."
|
68 |
|
69 |
+
st.title("Chatbot")
|
70 |
+
st.write("Type a message to chat with the bot")
|
71 |
|
72 |
+
message = st.text_input("Message")
|
73 |
+
history = []
|
74 |
+
system_message = st.text_input("System message")
|
75 |
+
max_tokens = st.slider("Max new tokens", 1, 2048, 2048)
|
76 |
+
temperature = st.slider("Temperature", 0.1, 4.0, 0.7)
|
77 |
+
top_p = st.slider("Top-P", 0.1, 1.0, 0.95)
|
78 |
+
|
79 |
+
if st.button("Send"):
|
80 |
+
response = respond(message, history, system_message, max_tokens, temperature, top_p)
|
81 |
+
st.write(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|