Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
def respond(message, history
|
| 5 |
client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
|
| 6 |
system_message = """You are BitAI (or Bit for short), a friendly chatbot created by the user "Sal".
|
| 7 |
Respond naturally. Respectfully refuse harmful requests, and if user insists, tell them to stop using the service."""
|
|
@@ -46,7 +46,7 @@ body { background-color:#000; font-family:'Arial',sans-serif; margin:0; padding:
|
|
| 46 |
.chat-message { border-radius:45px; padding:14px 18px; margin:8px 0; display:flex; flex-direction:column; opacity:0;}
|
| 47 |
.chat-message.user { background-color:#1f1f1f; color:#fff; align-items:flex-end;}
|
| 48 |
.chat-message.bot { background-color:#2b2b2b; color:#fff; align-items:flex-start;}
|
| 49 |
-
textarea { border:none; outline:none; border-radius:45px; padding:12px; background-color:#1a1a1a; color:#fff; font-size:16px; width:calc(100% -
|
| 50 |
.send-btn { border:none; border-radius:45px; background-color:#444; color:#fff; width:60px; height:60px; font-size:18px; display:flex; align-items:center; justify-content:center; cursor:pointer; margin-left:8px;}
|
| 51 |
.send-btn:hover { background-color:#555;}
|
| 52 |
.gr-button.gr-login { border-radius:45px !important; background-color:#222 !important; color:#fff !important; margin-bottom:15px;}
|
|
@@ -54,20 +54,19 @@ textarea { border:none; outline:none; border-radius:45px; padding:12px; backgrou
|
|
| 54 |
.input-container { display:flex; margin-top:10px; }
|
| 55 |
""") as demo:
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
gr.LoginButton()
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
# Campo de texto + botão enviar
|
| 64 |
-
with gr.Row(elem_classes=["input-container"]):
|
| 65 |
-
textbox = gr.Textbox(label="", placeholder="Escreva algo...", lines=1)
|
| 66 |
-
send = gr.Button("→", elem_classes=["send-btn"])
|
| 67 |
-
|
| 68 |
-
# Conecta botão ao chatbot
|
| 69 |
-
send.click(chatbot.submit, inputs=[textbox], outputs=[chatbot])
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
gr.HTML(fade_js)
|
| 72 |
|
| 73 |
if __name__=="__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
def respond(message, history, hf_token):
|
| 5 |
client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
|
| 6 |
system_message = """You are BitAI (or Bit for short), a friendly chatbot created by the user "Sal".
|
| 7 |
Respond naturally. Respectfully refuse harmful requests, and if user insists, tell them to stop using the service."""
|
|
|
|
| 46 |
.chat-message { border-radius:45px; padding:14px 18px; margin:8px 0; display:flex; flex-direction:column; opacity:0;}
|
| 47 |
.chat-message.user { background-color:#1f1f1f; color:#fff; align-items:flex-end;}
|
| 48 |
.chat-message.bot { background-color:#2b2b2b; color:#fff; align-items:flex-start;}
|
| 49 |
+
textarea { border:none; outline:none; border-radius:45px; padding:12px; background-color:#1a1a1a; color:#fff; font-size:16px; width:calc(100% - 70px); box-sizing:border-box; }
|
| 50 |
.send-btn { border:none; border-radius:45px; background-color:#444; color:#fff; width:60px; height:60px; font-size:18px; display:flex; align-items:center; justify-content:center; cursor:pointer; margin-left:8px;}
|
| 51 |
.send-btn:hover { background-color:#555;}
|
| 52 |
.gr-button.gr-login { border-radius:45px !important; background-color:#222 !important; color:#fff !important; margin-bottom:15px;}
|
|
|
|
| 54 |
.input-container { display:flex; margin-top:10px; }
|
| 55 |
""") as demo:
|
| 56 |
|
| 57 |
+
gr.LoginButton() # login direto
|
|
|
|
| 58 |
|
| 59 |
+
chatbot = gr.Chatbot(elem_classes=["chat-interface"])
|
| 60 |
+
textbox = gr.Textbox(label="", placeholder="Escreva algo...", lines=1)
|
| 61 |
+
send = gr.Button("→", elem_classes=["send-btn"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
# quando clicar enviar, atualiza o chatbot
|
| 64 |
+
def submit(message, history, hf_token):
|
| 65 |
+
for r in respond(message, history or [], hf_token):
|
| 66 |
+
yield history + [[message, r]]
|
| 67 |
+
|
| 68 |
+
send.click(submit, inputs=[textbox, chatbot, gr.State()], outputs=[chatbot])
|
| 69 |
+
|
| 70 |
gr.HTML(fade_js)
|
| 71 |
|
| 72 |
if __name__=="__main__":
|