Programer123 commited on
Commit
83d5461
·
verified ·
1 Parent(s): b98cef1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -39
app.py CHANGED
@@ -1,22 +1,13 @@
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",
@@ -52,41 +43,18 @@ with gr.Blocks(fill_height=True) as demo:
52
  gr.HTML("""
53
  <div id="title-box">
54
  <h1>🤖 Meu Chatbot</h1>
55
- <p>Um chatbot feito em Gradio com visual melhor e estrutura mais moderna.</p>
56
  </div>
57
  """)
58
 
59
- chatbot = gr.Chatbot(
60
- label="Conversa",
61
- height=500,
62
- type="messages"
63
- )
64
-
65
- with gr.Row():
66
- msg = gr.Textbox(
67
- placeholder="Escreve a tua mensagem aqui...",
68
- show_label=False,
69
- scale=8
70
- )
71
- send = gr.Button("Enviar", variant="primary", scale=1)
72
-
73
- clear = gr.ClearButton([msg, chatbot], value="Nova conversa")
74
-
75
- gr.Examples(
76
  examples=[
77
  "Olá, quem és tu?",
78
  "Explica-me o que é Gradio.",
79
  "Dá-me ideias para um projeto em Python.",
80
  "Como posso criar um chatbot mais bonito?"
81
- ],
82
- inputs=msg
83
- )
84
-
85
- msg.submit(user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
86
- bot_response, chatbot, chatbot
87
- )
88
- send.click(user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
89
- bot_response, chatbot, chatbot
90
  )
91
 
92
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import time
3
 
4
+ def responder(message, history):
5
+ resposta = f"Recebi a tua mensagem: '{message}'. Este é um chatbot principal em Gradio com visual simples e limpo."
 
 
 
 
 
 
 
 
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",
 
43
  gr.HTML("""
44
  <div id="title-box">
45
  <h1>🤖 Meu Chatbot</h1>
46
+ <p>Um chatbot feito em Gradio como interface principal.</p>
47
  </div>
48
  """)
49
 
50
+ gr.ChatInterface(
51
+ fn=responder,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  examples=[
53
  "Olá, quem és tu?",
54
  "Explica-me o que é Gradio.",
55
  "Dá-me ideias para um projeto em Python.",
56
  "Como posso criar um chatbot mais bonito?"
57
+ ]
 
 
 
 
 
 
 
 
58
  )
59
 
60
  if __name__ == "__main__":