Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,10 @@
|
|
1 |
-
import
|
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("HF_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/",
|
14 |
api_key=ACCESS_TOKEN,
|
@@ -37,7 +33,7 @@ def respond(
|
|
37 |
response = ""
|
38 |
|
39 |
for message in client.chat.completions.create(
|
40 |
-
model=
|
41 |
max_tokens=max_tokens,
|
42 |
stream=True,
|
43 |
temperature=temperature,
|
@@ -66,17 +62,32 @@ def respond(
|
|
66 |
print(f"Error: {e}")
|
67 |
yield "Error occurred. Please try again."
|
68 |
|
69 |
-
|
70 |
-
|
|
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
-
if
|
80 |
-
|
81 |
-
for resp in response:
|
82 |
-
st.write(resp)
|
|
|
1 |
+
import gradio as gr
|
2 |
from openai import OpenAI, APIError
|
3 |
import os
|
4 |
import tenacity
|
5 |
|
|
|
6 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
7 |
|
|
|
|
|
|
|
8 |
client = OpenAI(
|
9 |
base_url="https://api-inference.huggingface.co/v1/",
|
10 |
api_key=ACCESS_TOKEN,
|
|
|
33 |
response = ""
|
34 |
|
35 |
for message in client.chat.completions.create(
|
36 |
+
model="NousResearch/Hermes-3-Llama-3.1-8B",
|
37 |
max_tokens=max_tokens,
|
38 |
stream=True,
|
39 |
temperature=temperature,
|
|
|
62 |
print(f"Error: {e}")
|
63 |
yield "Error occurred. Please try again."
|
64 |
|
65 |
+
def launch_app():
|
66 |
+
try:
|
67 |
+
chatbot = gr.Chatbot(height=600)
|
68 |
|
69 |
+
demo = gr.ChatInterface(
|
70 |
+
respond,
|
71 |
+
additional_inputs=[
|
72 |
+
gr.Textbox(value="", label="System message"),
|
73 |
+
gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
|
74 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
75 |
+
gr.Slider(
|
76 |
+
minimum=0.1,
|
77 |
+
maximum=1.0,
|
78 |
+
value=0.95,
|
79 |
+
step=0.05,
|
80 |
+
label="Top-P",
|
81 |
+
),
|
82 |
+
|
83 |
+
],
|
84 |
+
fill_height=True,
|
85 |
+
chatbot=chatbot
|
86 |
+
)
|
87 |
+
demo.launch(show_error=True)
|
88 |
+
except KeyError as e:
|
89 |
+
print(f"Error: {e}")
|
90 |
+
print("Please try again.")
|
91 |
|
92 |
+
if __name__ == "__main__":
|
93 |
+
launch_app()
|
|
|
|