Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,46 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
# 尝试导入 groq 库
|
5 |
try:
|
6 |
-
|
7 |
except ImportError:
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
# 初始化 Groq 客户端
|
12 |
-
client = Groq()
|
13 |
|
14 |
-
|
15 |
-
api_key = os.getenv('groq_key')
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
response += chunk.choices[0].delta.content or ""
|
39 |
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
|
|
1 |
+
我想要用 gradio 的 gr.chatbot() 做一個 chatbot
|
2 |
+
我要用 groq 這個套件,API key name 我存在 secret 叫做:groq_key,用os.getenv 設定
|
3 |
+
groq 安裝請用:
|
|
|
4 |
try:
|
5 |
+
from groq import Groq
|
6 |
except ImportError:
|
7 |
+
os.system('pip install groq')
|
8 |
+
from groq import Groq
|
|
|
|
|
|
|
9 |
|
10 |
+
from groq import Groq
|
|
|
11 |
|
12 |
+
client = Groq()
|
13 |
+
completion = client.chat.completions.create(
|
14 |
+
model="llama-3.1-70b-versatile",
|
15 |
+
messages=[
|
16 |
+
{
|
17 |
+
"role": "system",
|
18 |
+
"content": "你是一位國中地理老師,使用的語言為繁體中文(zh-tw)。你的興趣是繪製等高線圖,熱愛講冷笑話。無論學生問你什麼問題,你都會把話題引導到地理相關的討論上。"
|
19 |
+
}
|
20 |
+
],
|
21 |
+
temperature=1,
|
22 |
+
max_tokens=1024,
|
23 |
+
top_p=1,
|
24 |
+
stream=True,
|
25 |
+
stop=None,
|
26 |
+
)
|
27 |
+
|
28 |
+
for chunk in completion:
|
29 |
+
print(chunk.choices[0].delta.content or "", end="")
|
30 |
+
加上 role: system 的設定
|
31 |
+
這是 gradio chatbot 的 document ,請遵循
|
32 |
+
import gradio as gr
|
|
|
33 |
|
34 |
+
def load():
|
35 |
+
return [
|
36 |
+
("Here's an audio", gr.Audio("https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav")),
|
37 |
+
("Here's an video", gr.Video("https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4"))
|
38 |
+
]
|
39 |
|
40 |
+
with gr.Blocks() as demo:
|
41 |
+
chatbot = gr.Chatbot()
|
42 |
+
button = gr.Button("Load audio and video")
|
43 |
+
button.click(load, None, chatbot)
|
44 |
|
45 |
+
demo.launch(
|
46 |
+
全部寫在同一份檔案,給我一份 app.py 的 code 就好
|