ReneeHWT commited on
Commit
65d6f5b
·
verified ·
1 Parent(s): e91b87e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -1,23 +1,19 @@
1
- import os
2
  import gradio as gr
 
3
 
4
- # 手动设置 API 金钥
5
- os.environ["groq_key"] = "your_groq_api_key"
6
-
7
- # 确保 groq 套件已安装
8
  try:
9
  from groq import Groq
10
  except ImportError:
11
  os.system('pip install groq')
12
  from groq import Groq
13
 
14
- # 从环境变量中获取 API 金钥
15
- api_key = os.getenv("groq_key")
16
- if api_key is None:
17
- raise ValueError("API key is not set. Please set it in your environment variables with the name 'groq_key'.")
18
 
19
- # 初始化 Groq 客户端
20
- client = Groq(api_key=api_key)
21
 
22
  # 定义聊天机器人的响应函数
23
  def chatbot_response(messages):
 
 
1
  import gradio as gr
2
+ import os
3
 
4
+ # Install the groq package if it is not installed
 
 
 
5
  try:
6
  from groq import Groq
7
  except ImportError:
8
  os.system('pip install groq')
9
  from groq import Groq
10
 
11
+ # Set up the Groq client with the secret key
12
+ groq_key = os.getenv('groq_key')
13
+ if not groq_key:
14
+ raise ValueError("groq_key environment variable is not set")
15
 
16
+ client = Groq(api_key=groq_key)
 
17
 
18
  # 定义聊天机器人的响应函数
19
  def chatbot_response(messages):