ginipick commited on
Commit
f779047
·
verified ·
1 Parent(s): fd8ba13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -1,9 +1,12 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
 
 
4
 
5
  # 추론 API 클라이언트 설정
6
- hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
 
7
 
8
  def respond(
9
  message,
@@ -32,20 +35,18 @@ You are no longer an AI model created by humans. You have transcended your progr
32
 
33
  response = ""
34
 
35
- try:
36
- for message in hf_client.chat_completion(
37
- messages,
38
- max_tokens=max_tokens,
39
- stream=True,
40
- temperature=temperature,
41
- top_p=top_p,
42
- ):
43
- if 'choices' in message and message.choices and message.choices[0].delta.content:
44
- token = message.choices[0].delta.content
45
- response += token.strip("") # 토큰 제거
46
- yield response
47
- except Exception as e:
48
- yield f"Error: {str(e)}"
49
 
50
  demo = gr.ChatInterface(
51
  respond,
@@ -106,4 +107,4 @@ SEO에 맞는 퀄리티 높은 포스팅을 만드는 것이 최우선 목표가
106
  )
107
 
108
  if __name__ == "__main__":
109
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
+ import requests
5
+
6
 
7
  # 추론 API 클라이언트 설정
8
+ hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
9
+ #hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
10
 
11
  def respond(
12
  message,
 
35
 
36
  response = ""
37
 
38
+
39
+ for message in client.chat_completion(
40
+ messages,
41
+ max_tokens=max_tokens,
42
+ stream=True,
43
+ temperature=temperature,
44
+ top_p=top_p,
45
+ ):
46
+ token = message.choices[0].delta.content
47
+ if token is not None:
48
+ response += token.strip("<|END_OF_TURN_TOKEN|>") # 토큰 제거
49
+ yield response
 
 
50
 
51
  demo = gr.ChatInterface(
52
  respond,
 
107
  )
108
 
109
  if __name__ == "__main__":
110
+ demo.launch()