CasperDylan commited on
Commit
951960f
·
verified ·
1 Parent(s): 698c406

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -28
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import os
 
2
  import gradio as gr
3
- from groq import Groq
4
 
5
  # 安裝 groq 套件
6
- os.system('pip install groq')
 
 
7
 
8
  # 初始化 Groq 客戶端
9
  groq_key = os.getenv("groq_key")
@@ -22,29 +24,4 @@ def chatbot_response(user_message):
22
  ]
23
 
24
  completion = client.chat.completions.create(
25
- model="llama-3.1-70b-versatile",
26
- messages=messages,
27
- temperature=1,
28
- max_tokens=1024,
29
- top_p=1,
30
- stream=False,
31
- stop=None,
32
- )
33
-
34
- response_message = completion.choices[0].message['content']
35
- return response_message
36
-
37
- # 建立 Gradio 界面
38
- with gr.Blocks() as demo:
39
- chatbot = gr.Chatbot()
40
- user_input = gr.Textbox(placeholder="輸入訊息...")
41
- send_button = gr.Button("發送")
42
-
43
- def user_message_handler(user_message, history):
44
- bot_response = chatbot_response(user_message)
45
- history.append((user_message, bot_response))
46
- return history, ""
47
-
48
- send_button.click(user_message_handler, [user_input, chatbot], [chatbot, user_input])
49
-
50
- demo.launch()
 
1
  import os
2
+ import subprocess
3
  import gradio as gr
 
4
 
5
  # 安裝 groq 套件
6
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'groq'])
7
+
8
+ from groq import Groq
9
 
10
  # 初始化 Groq 客戶端
11
  groq_key = os.getenv("groq_key")
 
24
  ]
25
 
26
  completion = client.chat.completions.create(
27
+ model