Spaces:
Sleeping
Sleeping
Fazeel Asghar
commited on
Commit
·
3671540
1
Parent(s):
61230db
Changed something
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ from groq import Groq
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
load_dotenv()
|
| 7 |
-
|
| 8 |
client = Groq()
|
| 9 |
session_memory_dict = {}
|
| 10 |
|
|
@@ -48,62 +47,91 @@ def clear_session(session_id):
|
|
| 48 |
return [], "gradio_default"
|
| 49 |
|
| 50 |
with gr.Blocks(css="""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
.chatbot {
|
|
|
|
| 52 |
display: flex;
|
| 53 |
flex-direction: column;
|
| 54 |
-
height:
|
| 55 |
overflow-y: auto;
|
| 56 |
-
padding:
|
|
|
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
.chatbot .message {
|
| 59 |
width: fit-content;
|
| 60 |
-
max-width:
|
| 61 |
-
padding: 12px
|
| 62 |
-
margin:
|
| 63 |
-
border-radius:
|
| 64 |
line-height: 1.5;
|
| 65 |
-
|
| 66 |
}
|
| 67 |
.chatbot .message.user {
|
| 68 |
-
background-color: #
|
| 69 |
-
color:
|
| 70 |
align-self: flex-end;
|
| 71 |
}
|
| 72 |
.chatbot .message.bot {
|
| 73 |
-
background-color: #
|
| 74 |
-
color: #
|
| 75 |
align-self: flex-start;
|
| 76 |
}
|
| 77 |
-
.
|
| 78 |
-
display: flex;
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
}
|
| 83 |
input, button {
|
| 84 |
font-size: 1rem;
|
| 85 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
""") as demo:
|
| 87 |
|
| 88 |
-
gr.Markdown("
|
| 89 |
|
| 90 |
state = gr.State([])
|
| 91 |
-
|
| 92 |
-
with gr.Row(elem_classes="input-row"):
|
| 93 |
-
user_input = gr.Textbox(
|
| 94 |
-
label="", placeholder="Type your message here...", lines=1, interactive=True
|
| 95 |
-
)
|
| 96 |
-
send_btn = gr.Button("Send", variant="primary")
|
| 97 |
-
|
| 98 |
-
# Chat area
|
| 99 |
chatbot = gr.Chatbot(elem_classes="chatbot")
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
| 103 |
session_id = gr.Textbox(label="Session ID", value="gradio_default", interactive=True)
|
| 104 |
clear_btn = gr.Button("Clear Chat")
|
| 105 |
|
| 106 |
-
# Interaction wiring
|
| 107 |
send_btn.click(fn=chat_interface, inputs=[user_input, state, session_id], outputs=[chatbot, user_input])
|
| 108 |
user_input.submit(fn=chat_interface, inputs=[user_input, state, session_id], outputs=[chatbot, user_input])
|
| 109 |
clear_btn.click(fn=clear_session, inputs=[session_id], outputs=[chatbot, session_id])
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
load_dotenv()
|
|
|
|
| 7 |
client = Groq()
|
| 8 |
session_memory_dict = {}
|
| 9 |
|
|
|
|
| 47 |
return [], "gradio_default"
|
| 48 |
|
| 49 |
with gr.Blocks(css="""
|
| 50 |
+
body {
|
| 51 |
+
background-color: #121212;
|
| 52 |
+
color: #E0E0E0;
|
| 53 |
+
font-family: 'Segoe UI', sans-serif;
|
| 54 |
+
}
|
| 55 |
+
.header {
|
| 56 |
+
text-align: center;
|
| 57 |
+
font-size: 1.8rem;
|
| 58 |
+
padding: 1rem;
|
| 59 |
+
background-color: #1F1F1F;
|
| 60 |
+
color: #ffffff;
|
| 61 |
+
border-bottom: 1px solid #333;
|
| 62 |
+
}
|
| 63 |
.chatbot {
|
| 64 |
+
flex: 1;
|
| 65 |
display: flex;
|
| 66 |
flex-direction: column;
|
| 67 |
+
height: 65vh;
|
| 68 |
overflow-y: auto;
|
| 69 |
+
padding: 1rem;
|
| 70 |
+
background-color: #1E1E1E;
|
| 71 |
+
border-radius: 12px;
|
| 72 |
+
margin-bottom: 1rem;
|
| 73 |
}
|
| 74 |
.chatbot .message {
|
| 75 |
width: fit-content;
|
| 76 |
+
max-width: 75%;
|
| 77 |
+
padding: 12px 18px;
|
| 78 |
+
margin: 8px 0;
|
| 79 |
+
border-radius: 16px;
|
| 80 |
line-height: 1.5;
|
| 81 |
+
word-break: break-word;
|
| 82 |
}
|
| 83 |
.chatbot .message.user {
|
| 84 |
+
background-color: #2979FF;
|
| 85 |
+
color: white;
|
| 86 |
align-self: flex-end;
|
| 87 |
}
|
| 88 |
.chatbot .message.bot {
|
| 89 |
+
background-color: #2C2C2C;
|
| 90 |
+
color: #E0E0E0;
|
| 91 |
align-self: flex-start;
|
| 92 |
}
|
| 93 |
+
.input-section {
|
| 94 |
+
display: flex;
|
| 95 |
+
gap: 10px;
|
| 96 |
+
align-items: center;
|
| 97 |
+
margin-top: auto;
|
| 98 |
}
|
| 99 |
input, button {
|
| 100 |
font-size: 1rem;
|
| 101 |
}
|
| 102 |
+
.send-button {
|
| 103 |
+
background-color: #2979FF;
|
| 104 |
+
color: white;
|
| 105 |
+
border: none;
|
| 106 |
+
padding: 10px 16px;
|
| 107 |
+
border-radius: 12px;
|
| 108 |
+
cursor: pointer;
|
| 109 |
+
}
|
| 110 |
+
.send-button:hover {
|
| 111 |
+
background-color: #5393FF;
|
| 112 |
+
}
|
| 113 |
+
.session-controls {
|
| 114 |
+
display: flex;
|
| 115 |
+
justify-content: space-between;
|
| 116 |
+
gap: 10px;
|
| 117 |
+
margin-top: 1rem;
|
| 118 |
+
}
|
| 119 |
""") as demo:
|
| 120 |
|
| 121 |
+
gr.Markdown("## 🤖 Smart Assistant Chat", elem_classes="header")
|
| 122 |
|
| 123 |
state = gr.State([])
|
| 124 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
chatbot = gr.Chatbot(elem_classes="chatbot")
|
| 126 |
|
| 127 |
+
with gr.Row(elem_classes="input-section"):
|
| 128 |
+
user_input = gr.Textbox(placeholder="Type your message...", lines=1, label="")
|
| 129 |
+
send_btn = gr.Button("Send", elem_classes="send-button")
|
| 130 |
+
|
| 131 |
+
with gr.Row(elem_classes="session-controls"):
|
| 132 |
session_id = gr.Textbox(label="Session ID", value="gradio_default", interactive=True)
|
| 133 |
clear_btn = gr.Button("Clear Chat")
|
| 134 |
|
|
|
|
| 135 |
send_btn.click(fn=chat_interface, inputs=[user_input, state, session_id], outputs=[chatbot, user_input])
|
| 136 |
user_input.submit(fn=chat_interface, inputs=[user_input, state, session_id], outputs=[chatbot, user_input])
|
| 137 |
clear_btn.click(fn=clear_session, inputs=[session_id], outputs=[chatbot, session_id])
|