Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from bot import chat
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
def chat_fn(message, history):
|
| 6 |
+
formatted_history = []
|
| 7 |
+
for user_msg, bot_msg in history:
|
| 8 |
+
formatted_history.append({"role": "user", "content": user_msg})
|
| 9 |
+
formatted_history.append({"role": "assistant", "content": bot_msg})
|
| 10 |
+
reply = chat(message, formatted_history)
|
| 11 |
+
return reply
|
| 12 |
+
|
| 13 |
+
with gr.Blocks(css="""
|
| 14 |
+
body {background: #f9fafb; font-family: 'Inter', sans-serif;}
|
| 15 |
+
#chatbot {
|
| 16 |
+
height: 50px;
|
| 17 |
+
overflow-y: auto;
|
| 18 |
+
background: white;
|
| 19 |
+
border-radius: 20px;
|
| 20 |
+
padding: 24px;
|
| 21 |
+
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
|
| 22 |
+
line-height: 1.6;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
/* USER messages */
|
| 26 |
+
.message.user {
|
| 27 |
+
background: linear-gradient(135deg,#2563eb,#1d4ed8);
|
| 28 |
+
color: white;
|
| 29 |
+
border-radius: 18px 18px 4px 18px;
|
| 30 |
+
padding: 14px 18px;
|
| 31 |
+
max-width: 70%;
|
| 32 |
+
margin-left: auto;
|
| 33 |
+
margin: 12px 0;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/* BOT messages */
|
| 37 |
+
.message.bot {
|
| 38 |
+
background: #f3f4f6;
|
| 39 |
+
color: #111827;
|
| 40 |
+
border-radius: 18px 18px 18px 4px;
|
| 41 |
+
padding: 14px 18px;
|
| 42 |
+
max-width: 70%;
|
| 43 |
+
margin-right: auto;
|
| 44 |
+
margin: 12px 0;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
#input-row {margin-top: 14px;}
|
| 48 |
+
.send-btn {
|
| 49 |
+
background: #2563eb !important;
|
| 50 |
+
color: white !important;
|
| 51 |
+
border-radius: 12px;
|
| 52 |
+
height: 48px;
|
| 53 |
+
}
|
| 54 |
+
h1 {text-align:center; font-size: 2rem; color: #111827; margin-bottom: 0.3rem;}
|
| 55 |
+
h2 {text-align:center; font-size: 1rem; font-weight: 400; color: #6b7280; margin-bottom: 1rem;}
|
| 56 |
+
""") as demo:
|
| 57 |
+
|
| 58 |
+
with gr.Column():
|
| 59 |
+
gr.HTML("<h1>💬 Chat with Shekar</h1>")
|
| 60 |
+
|
| 61 |
+
chatbot = gr.Chatbot(elem_id="chatbot", bubble_full_width=False, show_label=False)
|
| 62 |
+
|
| 63 |
+
with gr.Row(elem_id="input-row"):
|
| 64 |
+
msg = gr.Textbox(
|
| 65 |
+
placeholder="Type your message here...",
|
| 66 |
+
show_label=False,
|
| 67 |
+
container=False,
|
| 68 |
+
scale=8
|
| 69 |
+
)
|
| 70 |
+
submit_btn = gr.Button("➤", elem_classes="send-btn", scale=1)
|
| 71 |
+
|
| 72 |
+
def respond(message, history):
|
| 73 |
+
bot_reply = chat_fn(message, history)
|
| 74 |
+
history.append((message, bot_reply))
|
| 75 |
+
return history, ""
|
| 76 |
+
|
| 77 |
+
submit_btn.click(respond, [msg, chatbot], [chatbot, msg])
|
| 78 |
+
msg.submit(respond, [msg, chatbot], [chatbot, msg])
|
| 79 |
+
|
| 80 |
+
demo.launch()
|