Programer123 commited on
Commit
c9904d1
·
verified ·
1 Parent(s): 9bf8cef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -24
app.py CHANGED
@@ -1,13 +1,22 @@
1
  import gradio as gr
2
  import time
3
 
4
- def responder(message, history):
5
- resposta = f"Recebi a tua mensagem: '{message}'. Esta é uma resposta exemplo num chatbot em Gradio."
 
 
 
 
 
 
 
 
6
  texto = ""
7
  for palavra in resposta.split():
8
  texto += palavra + " "
 
9
  time.sleep(0.03)
10
- yield texto
11
 
12
  theme = gr.themes.Soft(
13
  primary_hue="blue",
@@ -39,7 +48,7 @@ custom_css = """
39
  footer {display: none !important;}
40
  """
41
 
42
- with gr.Blocks(theme=theme, css=custom_css, fill_height=True) as demo:
43
  gr.HTML("""
44
  <div id="title-box">
45
  <h1>🤖 Meu Chatbot</h1>
@@ -50,9 +59,7 @@ with gr.Blocks(theme=theme, css=custom_css, fill_height=True) as demo:
50
  chatbot = gr.Chatbot(
51
  label="Conversa",
52
  height=500,
53
- bubble_full_width=False,
54
  show_copy_button=True,
55
- avatar_images=(None, None),
56
  type="messages"
57
  )
58
 
@@ -77,23 +84,6 @@ with gr.Blocks(theme=theme, css=custom_css, fill_height=True) as demo:
77
  inputs=msg
78
  )
79
 
80
- def user_message(message, history):
81
- history = history or []
82
- history.append({"role": "user", "content": message})
83
- return "", history
84
-
85
- def bot_response(history):
86
- user_msg = history[-1]["content"]
87
- resposta = f"Recebi a tua mensagem: '{user_msg}'. Esta é uma resposta exemplo num chatbot em Gradio."
88
- history.append({"role": "assistant", "content": ""})
89
-
90
- texto = ""
91
- for palavra in resposta.split():
92
- texto += palavra + " "
93
- history[-1]["content"] = texto
94
- time.sleep(0.03)
95
- yield history
96
-
97
  msg.submit(user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
98
  bot_response, chatbot, chatbot
99
  )
@@ -102,4 +92,9 @@ with gr.Blocks(theme=theme, css=custom_css, fill_height=True) as demo:
102
  )
103
 
104
  if __name__ == "__main__":
105
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
1
  import gradio as gr
2
  import time
3
 
4
+ def user_message(message, history):
5
+ history = history or []
6
+ history.append({"role": "user", "content": message})
7
+ return "", history
8
+
9
+ def bot_response(history):
10
+ user_msg = history[-1]["content"]
11
+ resposta = f"Recebi a tua mensagem: '{user_msg}'. Esta é uma resposta exemplo num chatbot em Gradio."
12
+ history.append({"role": "assistant", "content": ""})
13
+
14
  texto = ""
15
  for palavra in resposta.split():
16
  texto += palavra + " "
17
+ history[-1]["content"] = texto
18
  time.sleep(0.03)
19
+ yield history
20
 
21
  theme = gr.themes.Soft(
22
  primary_hue="blue",
 
48
  footer {display: none !important;}
49
  """
50
 
51
+ with gr.Blocks(fill_height=True) as demo:
52
  gr.HTML("""
53
  <div id="title-box">
54
  <h1>🤖 Meu Chatbot</h1>
 
59
  chatbot = gr.Chatbot(
60
  label="Conversa",
61
  height=500,
 
62
  show_copy_button=True,
 
63
  type="messages"
64
  )
65
 
 
84
  inputs=msg
85
  )
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  msg.submit(user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
88
  bot_response, chatbot, chatbot
89
  )
 
92
  )
93
 
94
  if __name__ == "__main__":
95
+ demo.launch(
96
+ server_name="0.0.0.0",
97
+ server_port=7860,
98
+ theme=theme,
99
+ css=custom_css
100
+ )