Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,10 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
-
from groq import Groq
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
import os
|
8 |
-
os.environ['GROQ_API_KEY'] = "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"
|
9 |
-
client = Groq()
|
10 |
-
|
11 |
-
|
12 |
-
def respond(
|
13 |
-
message,
|
14 |
-
history: list[tuple[str, str]],
|
15 |
-
system_message,
|
16 |
-
max_tokens,
|
17 |
-
temperature,
|
18 |
-
top_p,
|
19 |
-
):
|
20 |
-
messages = [{"role": "system", "content": system_message}]
|
21 |
|
22 |
-
|
23 |
-
if val[0]:
|
24 |
-
messages.append({"role": "user", "content": val[0]})
|
25 |
-
if val[1]:
|
26 |
-
messages.append({"role": "assistant", "content": val[1]})
|
27 |
-
|
28 |
-
messages.append({"role": "user", "content": message})
|
29 |
-
|
30 |
-
response = ""
|
31 |
|
32 |
-
|
|
|
33 |
messages=[
|
34 |
{
|
35 |
"role": "user",
|
@@ -38,32 +13,14 @@ def respond(
|
|
38 |
],
|
39 |
model="llama3-8b-8192",
|
40 |
stream=False,
|
41 |
-
)
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
""
|
49 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
50 |
-
"""
|
51 |
-
demo = gr.ChatInterface(
|
52 |
-
respond,
|
53 |
-
additional_inputs=[
|
54 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
55 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
56 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
57 |
-
gr.Slider(
|
58 |
-
minimum=0.1,
|
59 |
-
maximum=1.0,
|
60 |
-
value=0.95,
|
61 |
-
step=0.05,
|
62 |
-
label="Top-p (nucleus sampling)",
|
63 |
-
),
|
64 |
-
],
|
65 |
)
|
66 |
-
|
67 |
-
|
68 |
if __name__ == "__main__":
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
os.environ['GROQ_API_KEY'] = "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"from groq import Groq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
client = Groq()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
def chatbot(prompt):
|
7 |
+
chat_completion = client.chat.completions.create(
|
8 |
messages=[
|
9 |
{
|
10 |
"role": "user",
|
|
|
13 |
],
|
14 |
model="llama3-8b-8192",
|
15 |
stream=False,
|
16 |
+
)
|
17 |
+
return chat_completion.choices[0].message.content
|
18 |
+
import gradio as gr
|
19 |
+
gradio_app = gr.Interface(
|
20 |
+
chatbot,
|
21 |
+
inputs=['text'],
|
22 |
+
outputs=['text'],
|
23 |
+
title="Harsh's Chatbot",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
)
|
|
|
|
|
25 |
if __name__ == "__main__":
|
26 |
+
gradio_app.launch(debug=True)
|