KaiShin1885 commited on
Commit
711f8c2
Β·
verified Β·
1 Parent(s): 4558cc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -44
app.py CHANGED
@@ -1,53 +1,20 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
4
- client = InferenceClient("CosmosRP-8k")
5
-
6
- def respond(
7
- message,
8
- history,
9
- system_message,
10
- max_tokens,
11
- temperature,
12
- top_p,
13
- ):
14
- messages = [{"role": "system", "content": system_message}]
15
-
16
- for val in history:
17
- if val[0]:
18
- messages.append({"role": "user", "content": val[0]})
19
  if val[1]:
20
- messages.append({"role": "assistant", "content": val[1]})
21
-
22
- messages.append({"role": "user", "content": message})
23
-
24
- response = ""
25
-
26
- for message in client.chat_completion(
27
- messages,
28
- max_tokens=max_tokens,
29
- stream=True,
30
- temperature=temperature,
31
- top_p=top_p,
32
- ):
33
- token = message.choices[0].delta.content
34
-
35
- response += token
36
- yield response
37
 
38
  demo = gr.Interface(
39
  fn=respond,
40
- inputs=[
41
- gr.Textbox(label="λ©”μ‹œμ§€"),
42
- gr.Textbox(label="μ‹œμŠ€ν…œ λ©”μ‹œμ§€"),
43
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="μ΅œλŒ€ μƒˆλ‘œμš΄ 토큰"),
44
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="μ˜¨λ„"),
45
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (Nucleus Sampling)"),
46
- ],
47
  outputs="text",
48
- title="μ±„νŒ…λ΄‡",
49
- description="이 μ±„νŒ…λ΄‡μ€ Hugging Face의 CosmosRP-8k λͺ¨λΈμ— μ˜ν•΄ κ΅¬λ™λ©λ‹ˆλ‹€.",
50
  )
51
 
52
- if __name__ == "__main__":
53
- demo.launch()
 
1
  import gradio as gr
 
2
 
3
+ def respond(val):
4
+ if len(val) > 1:
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  if val[1]:
6
+ # do something
7
+ pass
8
+ else:
9
+ # handle the case where val has only one element
10
+ pass
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  demo = gr.Interface(
13
  fn=respond,
14
+ inputs="text",
 
 
 
 
 
 
15
  outputs="text",
16
+ title="My App",
17
+ description="This is my app"
18
  )
19
 
20
+ demo.launch()