AMDF commited on
Commit
ab73867
Β·
verified Β·
1 Parent(s): 01e94dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -26
app.py CHANGED
@@ -2,32 +2,26 @@ import gradio as gr
2
  import requests
3
  import json
4
 
5
- # pip install openai
6
-
7
- from openai import OpenAI # openai==1.52.2
8
-
9
- client = OpenAI(
10
- api_key="up_S7cDxYLLt07RZDzCHBvGQnV0zqv4b",
11
- base_url="https://api.upstage.ai/v1"
12
- )
13
-
14
- stream = client.chat.completions.create(
15
- model="solar-pro2",
16
- messages=[
17
- {
18
- "role": "user",
19
- "content": "Hi, how are you?"
20
- }
21
- ],
22
- stream=True,
23
- )
24
-
25
- for chunk in stream:
26
- if chunk.choices[0].delta.content is not None:
27
- print(chunk.choices[0].delta.content, end="")
28
-
29
- # Use with stream=False
30
- # print(stream.choices[0].message.content)
31
 
32
  def chat_with_solar(message, history):
33
  """Solar Pro2와 λŒ€ν™”ν•˜λŠ” ν•¨μˆ˜"""
 
2
  import requests
3
  import json
4
 
5
+ import os
6
+ # .env νŒŒμΌμ— API_KEY="your_api_key_here" ν˜•νƒœλ‘œ μ €μž₯
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+ API_KEY = os.environ.get("up_S7cDxYLLt07RZDzCHBvGQnV0zqv4b")
11
+
12
+ if not API_KEY:
13
+ print("API ν‚€λ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€. ν™˜κ²½ λ³€μˆ˜λ₯Ό ν™•μΈν•΄μ£Όμ„Έμš”.")
14
+ # ν‚€κ°€ 없을 경우 ν”„λ‘œκ·Έλž¨ μ’…λ£Œ λ˜λŠ” μ—λŸ¬ 처리
15
+ exit()
16
+
17
+ # κΈ°μ‘΄ μ½”λ“œμ—μ„œ API_KEY λ³€μˆ˜λ₯Ό κ·ΈλŒ€λ‘œ μ‚¬μš©
18
+ API_URL = "https://api.upstage.ai/v1"
19
+ headers = {
20
+ "Authorization": f"Bearer {API_KEY}",
21
+ "Content-Type": "application/json"
22
+ }
23
+
24
+
 
 
 
 
 
 
25
 
26
  def chat_with_solar(message, history):
27
  """Solar Pro2와 λŒ€ν™”ν•˜λŠ” ν•¨μˆ˜"""