Tricia Nieva commited on
Commit
e7fe6f7
·
1 Parent(s): 37c119c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -33,6 +33,13 @@ def predict(input, history=[]):
33
  frequency_penalty=0,
34
  presence_penalty=0).tolist()
35
 
 
 
 
 
 
 
 
36
  history = response[Completion]
37
 
38
  # convert the tokens to text, and then split the responses into lines
@@ -40,6 +47,16 @@ def predict(input, history=[]):
40
  response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)] # convert to tuples of list
41
  return response, history
42
 
 
 
 
 
 
 
 
 
43
  gr.Interface(fn=predict,
44
- inputs=["text", "state"],
45
- outputs=["chatbot", "state"]).launch()
 
 
 
33
  frequency_penalty=0,
34
  presence_penalty=0).tolist()
35
 
36
+ # write some HTML
37
+ html = "<div class='chatbot'>"
38
+ for m, msg in enumerate(response):
39
+ cls = "user" if m%2 == 0 else "bot"
40
+ html += "<div class='msg {}'> {}</div>".format(cls, msg)
41
+ html += "</div>"
42
+
43
  history = response[Completion]
44
 
45
  # convert the tokens to text, and then split the responses into lines
 
47
  response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)] # convert to tuples of list
48
  return response, history
49
 
50
+ css = """
51
+ .chatbox {display:flex;flex-direction:column}
52
+ .msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
53
+ .msg.user {background-color:cornflowerblue;color:white}
54
+ .msg.bot {background-color:lightgray;align-self:self-end}
55
+ .footer {display:none !important}
56
+ """
57
+
58
  gr.Interface(fn=predict,
59
+ theme="default",
60
+ inputs=[gr.inputs.Textbox(placeholder="I'm AI-DHD - ask me anything!"), "state"],
61
+ outputs=["html", "state"],
62
+ css=css).launch()