abidlabs HF staff commited on
Commit
8caab2e
1 Parent(s): 565004c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -15,14 +15,30 @@ def predict(input, history=[]):
15
  history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
16
 
17
  # convert the tokens to text, and then split the responses into lines
18
- response = tokenizer.decode(history[0]).replace("<|endoftext|>", "\n")
 
19
 
20
- return response, history
 
 
 
 
 
 
 
21
 
22
  import gradio as gr
23
 
 
 
 
 
 
 
 
24
  gr.Interface(fn=predict,
25
  theme="default",
 
26
  inputs=["text", "state"],
27
  outputs=["text", "state"]).launch()
28
 
 
15
  history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
16
 
17
  # convert the tokens to text, and then split the responses into lines
18
+ response = tokenizer.decode(history[0]).split("<|endoftext|>")
19
+ response.remove("")
20
 
21
+ # write some HTML
22
+ html = "<div class='chatbot'>"
23
+ for m, msg in enumerate(response):
24
+ cls = "user" if m%2 == 0 else "bot"
25
+ html += "<div class='msg {}'> {}</div>".format(cls, msg)
26
+ html += "</div>"
27
+
28
+ return html, history
29
 
30
  import gradio as gr
31
 
32
+ css = """
33
+ .chatbox {display:flex;flex-direction:column}
34
+ .msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
35
+ .msg.user {background-color:cornflowerblue;color:white}
36
+ .msg.bot {background-color:lightgray;align-self:self-end}
37
+ """
38
+
39
  gr.Interface(fn=predict,
40
  theme="default",
41
+ css=css,
42
  inputs=["text", "state"],
43
  outputs=["text", "state"]).launch()
44