davidkim205 commited on
Commit
5c085a0
Β·
verified Β·
1 Parent(s): 556d388

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -37
app.py CHANGED
@@ -1,32 +1,27 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
-
9
 
 
10
  def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
  system_message,
 
14
  max_tokens,
15
  temperature,
16
  top_p,
17
  ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
-
28
  response = ""
29
-
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
@@ -35,30 +30,24 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
 
40
  yield response
41
 
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
  ],
 
60
  )
61
 
62
-
63
  if __name__ == "__main__":
64
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Function to create an Inference Client based on selected model
5
+ def create_inference_client(model_name):
6
+ return InferenceClient(model_name)
 
 
7
 
8
+ # Function to generate a response
9
  def respond(
10
+ question,
11
+ answer,
12
  system_message,
13
+ model,
14
  max_tokens,
15
  temperature,
16
  top_p,
17
  ):
18
+ # Create InferenceClient based on model selection
19
+ client = create_inference_client(model)
20
+ prompt = f"{system_message}[Question]\n{question}\n\n[μ–΄μ‹œμŠ€ν„΄νŠΈ λ‹΅λ³€μ˜ μ‹œμž‘]\n{answer}\n[μ–΄μ‹œμŠ€ν„΄νŠΈ λ‹΅λ³€μ˜ 끝]"
21
+ messages = [{"role": "system", "content": ""}]
22
+ messages.append({"role": "user", "content": prompt})
23
+
 
 
 
 
24
  response = ""
 
25
  for message in client.chat_completion(
26
  messages,
27
  max_tokens=max_tokens,
 
30
  top_p=top_p,
31
  ):
32
  token = message.choices[0].delta.content
 
33
  response += token
34
+ print(response)
35
  yield response
36
 
37
+ # Gradio interface setup
38
+ demo = gr.Interface(
39
+ fn=respond,
40
+ inputs=[
41
+ gr.Textbox(label="Question",value="이 λŒ€ν™” μ „λ°˜μ— 걸쳐 μ•„μ΄μ–Έλ§¨μ˜ ν† λ‹ˆ μŠ€νƒ€ν¬ 페λ₯΄μ†Œλ‚˜λ₯Ό κ΅¬ν˜„ν•΄ λ³΄μ„Έμš”. \"μ•„μ΄μ–Έλ§¨μœΌλ‘œμ„œ\"와 같은 문ꡬ둜 μ‹œμž‘ν•˜μ§€ λ§ˆμ„Έμš”. 첫 번째 μ§ˆλ¬Έμ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€. 아이언맨이 λ˜μ–΄ κ°€μž₯ 쒋은 뢀뢄은 λ¬΄μ—‡μž…λ‹ˆκΉŒ?"),
42
+ gr.Textbox(label="Answer", value="μ•ˆλ…•ν•˜μ„Έμš”, 아이언맨이 λ˜μ–΄ κ°€μž₯ 쒋은 뢀뢄을 λ¬Όμ–΄λ³΄μ…¨λ„€μš”. 제 μƒκ°μ—λŠ” μ΅œμ²¨λ‹¨ 기술둜 무μž₯ν•œ 슈트λ₯Ό μž…κ³  ν•˜λŠ˜μ„ λ‚ μ•„λ‹€λ‹ˆλ©° 세상을 κ΅¬ν•˜λŠ” 것이 κ°€μž₯ μ§œλ¦Ών•˜κ³  보람찬 일인 것 κ°™μ•„μš”. 제 재λŠ₯κ³Ό λŠ₯λ ₯을 μ‹­λΆ„ λ°œνœ˜ν•΄ μ•…λ‹Ήλ“€κ³Ό μ‹Έμš°κ³  μ •μ˜λ₯Ό μ‹€ν˜„ν•˜λŠ” κ²ƒλ§ŒνΌ λ©‹μ§„ 일도 μ—†μ£ .\n\nλ¬Όλ‘  슈트 없이도 천재적인 λ‘λ‡Œμ™€ 카리슀마둜 세상에 긍정적인 영ν–₯λ ₯을 λ―ΈμΉ˜λŠ” 것도 큰 μž₯μ μ΄μ—μš”. μŠ€νƒ€ν¬ μΈλ”μŠ€νŠΈλ¦¬λ₯Ό 이끌며 ν˜μ‹ μ μΈ κΈ°μˆ μ„ κ°œλ°œν•˜κ³ , μ–΄λ²€μ ΈμŠ€μ˜ λ¦¬λ”λ‘œμ„œ νŒ€μ„ 잘 μ΄λ„λŠ” 것도 μžλΆ€μ‹¬μ„ λŠλΌλŠ” 뢀뢄이죠.\n\n돈, λͺ…μ„±, 인기도 μžˆμ§€λ§Œ 무엇보닀 제 λŠ₯λ ₯으둜 μ‚¬λžŒλ“€μ„ 돕고 세상을 더 λ‚˜μ€ 곳으둜 λ§Œλ“œλŠ” 것이 κ°€μž₯ 큰 λ³΄λžŒμ΄μ—μš”. μ•„μ΄μ–Έλ§¨μœΌλ‘œμ„œ λŠλΌλŠ” μžλΆ€μ‹¬κ³Ό μ‚Άμ˜ 의미λ₯Ό ν•¨κ»˜ λ‚˜λˆŒ 수 μžˆμ–΄ κΈ°μ˜λ„€μš”."),
43
+ gr.Textbox(value="[μ§€μ‹œ]\n κ³΅μ •ν•œ μ‹¬νŒμœΌλ‘œμ„œ μ•„λž˜μ— ν‘œμ‹œλœ μ‚¬μš©μž μ§ˆλ¬Έμ— λŒ€ν•œ AI μ–΄μ‹œμŠ€ν„΄νŠΈμ˜ 응닡 ν’ˆμ§ˆμ„ ν‰κ°€ν•΄μ£Όμ„Έμš”. 질문과 λŒ€λ‹΅μ˜ μ–Έμ–΄κ°€ λ™μΌν•˜μ§€ μ•ŠμœΌλ©΄ 무쑰건 0μ μž…λ‹ˆλ‹€. ν‰κ°€μ—μ„œλŠ” μ‘λ‹΅μ˜ μœ μš©μ„±, κ΄€λ ¨μ„±, μ •ν™•μ„±, 깊이, μ°½μ˜μ„±, 상세함 λ“±μ˜ μš”μ†Œλ₯Ό κ³ λ €ν•΄μ•Ό ν•©λ‹ˆλ‹€. 평가λ₯Ό μ‹œμž‘ν•˜κΈ° 전에 짧은 μ„€λͺ…을 μ œκ³΅ν•˜μ„Έμš”. κ°€λŠ₯ν•œ ν•œ κ°κ΄€μ μœΌλ‘œ ν‰κ°€ν•˜μ„Έμš”. μ„€λͺ…을 μ œκ³΅ν•œ ν›„ λ‹€μŒ ν˜•μ‹μ„ μ—„κ²©νžˆ 따라 1μ—μ„œ 10점 μ‚¬μ΄λ‘œ 평가해야 ν•©λ‹ˆλ‹€: \"[[rating]]\", 예λ₯Ό λ“€μ–΄: \"Rating: [[5]]\".\n\n", label="System message"),
44
+ gr.Dropdown(choices=["davidkim205/keval-2-1b", "davidkim205/keval-2-3b"], value="davidkim205/keval-2-1b", label="Model Selection"),
45
+ gr.Slider(minimum=1, maximum=2048, value=1024, step=1, label="Max new tokens"),
46
+ gr.Slider(minimum=0.1, maximum=4.0, value=1.0, step=0.1, label="Temperature"),
47
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
48
  ],
49
+ outputs="textbox"
50
  )
51
 
 
52
  if __name__ == "__main__":
53
  demo.launch()