seawolf2357 commited on
Commit
f18ba88
โ€ข
1 Parent(s): 1f29b82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -1,25 +1,21 @@
1
-
2
  import gradio as gr
3
  import requests
4
  import os
5
 
6
- #import subprocess
7
- #subprocess.run(["huggingface-cli", "login", "--token", HUGGINGFACE_API_TOKEN_V])
8
-
9
- TOKEN = os.getenv("HUGGINGFACE_API_TOKEN_V")
10
 
11
- # Check if the API token is set
12
  if not TOKEN:
13
  raise ValueError("API token is not set. Please set the HUGGINGFACE_API_TOKEN environment variable.")
14
 
15
-
16
  def respond(
17
  message,
18
  history: list[tuple[str, str]],
19
- system_message,
20
- max_tokens,
21
- temperature,
22
- top_p,
23
  ):
24
  messages = [{"role": "system", "content": system_message}]
25
 
@@ -49,8 +45,12 @@ def respond(
49
  response_text = ""
50
  for chunk in response.iter_content(chunk_size=None):
51
  if chunk:
52
- response_text += chunk.decode('utf-8')
53
- yield response_text
 
 
 
 
54
 
55
  theme="Nymbo/Nymbo_Theme"
56
 
@@ -58,7 +58,7 @@ demo = gr.ChatInterface(
58
  respond,
59
  theme=theme,
60
  additional_inputs=[
61
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
62
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
63
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
64
  gr.Slider(
@@ -72,4 +72,4 @@ demo = gr.ChatInterface(
72
  )
73
 
74
  if __name__ == "__main__":
75
- demo.launch()
 
 
1
  import gradio as gr
2
  import requests
3
  import os
4
 
5
+ # ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ API ํ† ํฐ ๊ฐ€์ ธ์˜ค๊ธฐ
6
+ TOKEN = os.getenv("HUGGINGFACE_API_TOKEN")
 
 
7
 
8
+ # API ํ† ํฐ์ด ์„ค์ •๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธ
9
  if not TOKEN:
10
  raise ValueError("API token is not set. Please set the HUGGINGFACE_API_TOKEN environment variable.")
11
 
 
12
  def respond(
13
  message,
14
  history: list[tuple[str, str]],
15
+ system_message="๋„ˆ์˜ ์ด๋ฆ„์€ ํ™๊ธธ๋™์ด๋‹ค",
16
+ max_tokens=512,
17
+ temperature=0.7,
18
+ top_p=0.95,
19
  ):
20
  messages = [{"role": "system", "content": system_message}]
21
 
 
45
  response_text = ""
46
  for chunk in response.iter_content(chunk_size=None):
47
  if chunk:
48
+ chunk_data = chunk.decode('utf-8')
49
+ response_json = json.loads(chunk_data)
50
+ # content ์˜์—ญ๋งŒ ์ถœ๋ ฅ
51
+ if "choices" in response_json:
52
+ content = response_json["choices"][0]["message"]["content"]
53
+ yield content
54
 
55
  theme="Nymbo/Nymbo_Theme"
56
 
 
58
  respond,
59
  theme=theme,
60
  additional_inputs=[
61
+ gr.Textbox(value="๋„ˆ์˜ ์ด๋ฆ„์€ ํ™๊ธธ๋™์ด๋‹ค", label="System message"),
62
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
63
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
64
  gr.Slider(
 
72
  )
73
 
74
  if __name__ == "__main__":
75
+ demo.launch()