Carina1025 commited on
Commit
97d0683
1 Parent(s): 3246582

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -1,9 +1,19 @@
1
  import os
2
- import gradio as gr
3
- from groq import Groq
 
 
 
 
4
 
5
- # 安裝 groq 套件
6
- os.system('pip install groq')
 
 
 
 
 
 
7
 
8
  # 從環境變量中獲取 API 密鑰
9
  api_key = os.getenv('groq_key')
 
1
  import os
2
+ import subprocess
3
+ import sys
4
+
5
+ # 確保 groq 套件已安裝
6
+ def install(package):
7
+ subprocess.check_call([sys.executable, "-m", "pip", "install", package])
8
 
9
+ try:
10
+ from groq import Groq
11
+ except ImportError:
12
+ install("groq")
13
+ from groq import Groq
14
+
15
+ import gradio as gr
16
+ import random
17
 
18
  # 從環境變量中獲取 API 密鑰
19
  api_key = os.getenv('groq_key')