Spaces:
Running
on
Zero
Running
on
Zero
Ritvik
commited on
Commit
·
ec599bd
1
Parent(s):
afbf124
Updated app.py and requirements.txt
Browse files- app.py +25 -41
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,64 +1,48 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
-
|
10 |
-
def respond(
|
11 |
-
message,
|
12 |
-
history: list[tuple[str, str]],
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
for
|
21 |
-
if
|
22 |
-
messages.append({"role": "user", "content":
|
23 |
-
if
|
24 |
-
messages.append({"role": "assistant", "content":
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
temperature=temperature,
|
|
|
35 |
top_p=top_p,
|
36 |
-
|
37 |
-
|
|
|
38 |
|
|
|
|
|
|
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
48 |
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a friendly
|
50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from groq import Groq
|
3 |
+
import os
|
4 |
|
5 |
+
# Set your Groq API key
|
6 |
+
API_KEY = os.getenv("API_KEY")
|
7 |
+
client = Groq(api_key=API_KEY) # Pass API key explicitly
|
|
|
8 |
|
9 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
messages = [{"role": "system", "content": system_message}]
|
11 |
|
12 |
+
for user_input, bot_response in history:
|
13 |
+
if user_input:
|
14 |
+
messages.append({"role": "user", "content": user_input})
|
15 |
+
if bot_response:
|
16 |
+
messages.append({"role": "assistant", "content": bot_response})
|
17 |
|
18 |
messages.append({"role": "user", "content": message})
|
19 |
|
20 |
+
completion = client.chat.completions.create(
|
21 |
+
model="mixtral-8x7b-32768",
|
22 |
+
messages=messages,
|
|
|
|
|
|
|
23 |
temperature=temperature,
|
24 |
+
max_completion_tokens=max_tokens,
|
25 |
top_p=top_p,
|
26 |
+
stream=True,
|
27 |
+
stop=None,
|
28 |
+
)
|
29 |
|
30 |
+
response = ""
|
31 |
+
for chunk in completion:
|
32 |
+
token = chunk.choices[0].delta.content or ""
|
33 |
response += token
|
34 |
yield response
|
35 |
|
36 |
+
# Gradio Interface
|
|
|
|
|
|
|
37 |
demo = gr.ChatInterface(
|
38 |
respond,
|
39 |
additional_inputs=[
|
40 |
+
gr.Textbox(value="You are a friendly AI assistant.", label="System message"),
|
41 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
42 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
43 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
],
|
45 |
)
|
46 |
|
|
|
47 |
if __name__ == "__main__":
|
48 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
huggingface_hub==0.25.2
|
|
|
|
|
|
1 |
+
huggingface_hub==0.25.2
|
2 |
+
groq
|
3 |
+
gradio
|