aliceblue11 commited on
Commit
398cd15
·
verified ·
1 Parent(s): e1ec564

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
  from typing import Optional
4
 
5
  #############################
@@ -9,12 +10,14 @@ from typing import Optional
9
  # Cohere Command R+ 모델 ID 정의
10
  COHERE_MODEL = "CohereForAI/c4ai-command-r-plus-08-2024"
11
 
12
- def get_client(hf_token):
13
  """
14
  Cohere Command R+ 모델을 위한 InferenceClient 생성.
 
15
  """
 
16
  if not hf_token:
17
- raise ValueError("HuggingFace API 토큰이 필요합니다.")
18
  return InferenceClient(COHERE_MODEL, token=hf_token)
19
 
20
  def respond_cohere_qna(
@@ -22,14 +25,13 @@ def respond_cohere_qna(
22
  system_message: str,
23
  max_tokens: int,
24
  temperature: float,
25
- top_p: float,
26
- hf_token: str
27
  ):
28
  """
29
  Cohere Command R+ 모델을 이용해 한 번의 질문(question)에 대한 답변을 반환하는 함수.
30
  """
31
  try:
32
- client = get_client(hf_token)
33
  except ValueError as e:
34
  return f"오류: {str(e)}"
35
 
@@ -75,7 +77,7 @@ with gr.Blocks() as demo:
75
  # 전송 버튼
76
  submit_button = gr.Button("생성")
77
 
78
- def generate_blog(tone, ref1, ref2, ref3, hf_token):
79
  # 참조글을 합쳐서 질문 구성
80
  question = f"말투: {tone}\n참조글1: {ref1}\n참조글2: {ref2}\n참조글3: {ref3}"
81
  system_message = "블로그 글을 생성해주세요. 주어진 참조글을 바탕으로 요청된 말투에 맞게 작성하세요."
@@ -84,8 +86,7 @@ with gr.Blocks() as demo:
84
  system_message=system_message,
85
  max_tokens=1000,
86
  temperature=0.7,
87
- top_p=0.95,
88
- hf_token=hf_token
89
  )
90
 
91
  submit_button.click(
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import os
4
  from typing import Optional
5
 
6
  #############################
 
10
  # Cohere Command R+ 모델 ID 정의
11
  COHERE_MODEL = "CohereForAI/c4ai-command-r-plus-08-2024"
12
 
13
+ def get_client():
14
  """
15
  Cohere Command R+ 모델을 위한 InferenceClient 생성.
16
+ 환경 변수에서 HuggingFace API 토큰을 가져옴.
17
  """
18
+ hf_token = os.getenv("HUGGINGFACE_TOKEN")
19
  if not hf_token:
20
+ raise ValueError("HuggingFace API 토큰이 환경 변수에 설정되지 않았습니다.")
21
  return InferenceClient(COHERE_MODEL, token=hf_token)
22
 
23
  def respond_cohere_qna(
 
25
  system_message: str,
26
  max_tokens: int,
27
  temperature: float,
28
+ top_p: float
 
29
  ):
30
  """
31
  Cohere Command R+ 모델을 이용해 한 번의 질문(question)에 대한 답변을 반환하는 함수.
32
  """
33
  try:
34
+ client = get_client()
35
  except ValueError as e:
36
  return f"오류: {str(e)}"
37
 
 
77
  # 전송 버튼
78
  submit_button = gr.Button("생성")
79
 
80
+ def generate_blog(tone, ref1, ref2, ref3):
81
  # 참조글을 합쳐서 질문 구성
82
  question = f"말투: {tone}\n참조글1: {ref1}\n참조글2: {ref2}\n참조글3: {ref3}"
83
  system_message = "블로그 글을 생성해주세요. 주어진 참조글을 바탕으로 요청된 말투에 맞게 작성하세요."
 
86
  system_message=system_message,
87
  max_tokens=1000,
88
  temperature=0.7,
89
+ top_p=0.95
 
90
  )
91
 
92
  submit_button.click(