Spaces:
Runtime error
Runtime error
oscarwang2
commited on
Commit
•
473c6b3
1
Parent(s):
ed0fe5c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from groq import Groq
|
3 |
+
|
4 |
+
# Initialize Groq client
|
5 |
+
client = Groq()
|
6 |
+
|
7 |
+
# Function to handle the chat completion
|
8 |
+
def chat_with_bot(user_message):
|
9 |
+
completion = client.chat.completions.create(
|
10 |
+
model="llama-3.1-70b-versatile",
|
11 |
+
messages=[
|
12 |
+
{
|
13 |
+
"role": "user",
|
14 |
+
"content": user_message
|
15 |
+
}
|
16 |
+
],
|
17 |
+
temperature=1,
|
18 |
+
max_tokens=1024,
|
19 |
+
top_p=1,
|
20 |
+
stream=True,
|
21 |
+
stop=None,
|
22 |
+
)
|
23 |
+
|
24 |
+
# Collect the response
|
25 |
+
response = ""
|
26 |
+
for chunk in completion:
|
27 |
+
response += chunk.choices[0].delta.content or ""
|
28 |
+
|
29 |
+
return response
|
30 |
+
|
31 |
+
# Set up Gradio interface
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=chat_with_bot,
|
34 |
+
inputs="text",
|
35 |
+
outputs="text",
|
36 |
+
title="AI Chatbot",
|
37 |
+
description="Chat with Llama 3.1 70B",
|
38 |
+
)
|
39 |
+
|
40 |
+
# Launch the app
|
41 |
+
iface.launch()
|