chansung commited on
Commit
d87df45
1 Parent(s): a63e050

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +51 -6
app/main.py CHANGED
@@ -1,13 +1,58 @@
1
  import gradio as gr
2
- from text_generation import Client
 
3
 
4
  endpoint_url = "http://127.0.0.1:8080"
5
- client = Client(endpoint_url)
6
 
7
- text = client.generate("Why is the sky blue?").generated_text
8
- print(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- with gr.Blocks() as demo:
11
- gr.Markdown(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  demo.queue().launch(server_name="0.0.0.0", server_port=3000)
 
1
  import gradio as gr
2
+ from text_generation import AsyncClient
3
+ from text_generation.types import Message
4
 
5
  endpoint_url = "http://127.0.0.1:8080"
6
+ client = AsyncClient(endpoint_url)
7
 
8
+ """
9
+ frequency_penalty: Optional[float] = None,
10
+ logit_bias: Optional[List[float]] = None,
11
+ logprobs: Optional[bool] = None,
12
+ top_logprobs: Optional[int] = None,
13
+ max_tokens: Optional[int] = None,
14
+ n: Optional[int] = None,
15
+ presence_penalty: Optional[float] = None,
16
+ stream: bool = False,
17
+ seed: Optional[int] = None,
18
+ temperature: Optional[float] = None,
19
+ top_p: Optional[float] = None,
20
+ tools: Optional[List[Tool]] = None,
21
+ tool_choice: Optional[str] = None,
22
+ """
23
 
24
+ def _default_parameters():
25
+ return {
26
+ "max_tokens": 256,
27
+ "stream": True,
28
+ "temperature": 0.9,
29
+ }
30
+
31
+ def _translate_messages(history):
32
+ messages = []
33
+
34
+ for conv in history:
35
+ messages.append(Message(role="user", content=conv[0]))
36
+ messages.append(Message(role="assistant", content=conv[1]))
37
+
38
+ return messages
39
+
40
+ async def echo(message, history):
41
+ parameters = _default_parameters()
42
+ messages = _translate_messages(history)
43
+
44
+ history.append([message, ""])
45
+ full_resp = ""
46
+ async for resp in client.chat(messages=messages, **parameters):
47
+ full_resp = full_resp + resp.choices[0].delta.content
48
+ history[-1][1] = full_resp
49
+ yield history
50
+
51
+ demo = gr.ChatInterface(
52
+ fn=echo,
53
+ examples=[{"text": "hello"}, {"text": "hola"}, {"text": "merhaba"}],
54
+ title="Echo Bot",
55
+ multimodal=False
56
+ )
57
 
58
  demo.queue().launch(server_name="0.0.0.0", server_port=3000)