Spaces:
Sleeping
Sleeping
Fazeel Asghar
commited on
Commit
·
44c3464
1
Parent(s):
c9ff9b4
Changes in the interface 2
Browse files
app.py
CHANGED
|
@@ -48,32 +48,54 @@ def chat_logic(session_id: str, user_input: str):
|
|
| 48 |
print(f"[Session: {session_id}] AI Response: {ai_response}")
|
| 49 |
return ai_response
|
| 50 |
|
| 51 |
-
# UI logic for message display
|
| 52 |
def chat_interface(user_input, chat_history, session_id):
|
| 53 |
ai_reply = chat_logic(session_id, user_input)
|
| 54 |
chat_history.append((user_input, ai_reply))
|
| 55 |
return chat_history, ""
|
| 56 |
|
| 57 |
-
# Clear session memory
|
| 58 |
def clear_session(session_id):
|
| 59 |
session_memory_dict.pop(session_id, None)
|
| 60 |
return [], "gradio_default"
|
| 61 |
|
| 62 |
with gr.Blocks(css="""
|
| 63 |
-
.chatbot .message.user {
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
""") as demo:
|
| 66 |
-
gr.Markdown("
|
| 67 |
-
|
|
|
|
|
|
|
| 68 |
with gr.Row():
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
-
chatbot = gr.Chatbot(label="Chat
|
| 73 |
-
user_input = gr.Textbox(label="Type your message...", placeholder="Message...", lines=1)
|
| 74 |
-
send_btn = gr.Button("Send", variant="primary")
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
send_btn.click(
|
| 79 |
fn=chat_interface,
|
|
|
|
| 48 |
print(f"[Session: {session_id}] AI Response: {ai_response}")
|
| 49 |
return ai_response
|
| 50 |
|
|
|
|
| 51 |
def chat_interface(user_input, chat_history, session_id):
|
| 52 |
ai_reply = chat_logic(session_id, user_input)
|
| 53 |
chat_history.append((user_input, ai_reply))
|
| 54 |
return chat_history, ""
|
| 55 |
|
|
|
|
| 56 |
def clear_session(session_id):
|
| 57 |
session_memory_dict.pop(session_id, None)
|
| 58 |
return [], "gradio_default"
|
| 59 |
|
| 60 |
with gr.Blocks(css="""
|
| 61 |
+
.chatbot .message.user {
|
| 62 |
+
background-color: #25D366;
|
| 63 |
+
color: white;
|
| 64 |
+
border-radius: 18px;
|
| 65 |
+
padding: 10px;
|
| 66 |
+
max-width: 75%;
|
| 67 |
+
margin: 5px 0;
|
| 68 |
+
align-self: flex-end;
|
| 69 |
+
}
|
| 70 |
+
.chatbot .message.bot {
|
| 71 |
+
background-color: #f1f0f0;
|
| 72 |
+
color: black;
|
| 73 |
+
border-radius: 18px;
|
| 74 |
+
padding: 10px;
|
| 75 |
+
max-width: 75%;
|
| 76 |
+
margin: 5px 0;
|
| 77 |
+
align-self: flex-start;
|
| 78 |
+
}
|
| 79 |
+
.chatbot {
|
| 80 |
+
font-family: "Segoe UI", sans-serif;
|
| 81 |
+
font-size: 16px;
|
| 82 |
+
display: flex;
|
| 83 |
+
flex-direction: column;
|
| 84 |
+
}
|
| 85 |
""") as demo:
|
| 86 |
+
gr.Markdown("## 💬 WhatsApp-style AI Chat (Powered by Groq LLaMA3)")
|
| 87 |
+
|
| 88 |
+
state = gr.State([])
|
| 89 |
+
|
| 90 |
with gr.Row():
|
| 91 |
+
user_input = gr.Textbox(label="Type your message...", placeholder="Write a message...", lines=1)
|
| 92 |
+
send_btn = gr.Button("📤 Send", variant="primary")
|
| 93 |
|
| 94 |
+
chatbot = gr.Chatbot(label="Chat", elem_classes="chatbot")
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
with gr.Row():
|
| 97 |
+
session_id = gr.Textbox(label="Session ID", value="gradio_default", interactive=True)
|
| 98 |
+
clear_btn = gr.Button("🔄 Clear Session")
|
| 99 |
|
| 100 |
send_btn.click(
|
| 101 |
fn=chat_interface,
|