Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Function to generate
|
| 5 |
def chatbot(user_input, history):
|
| 6 |
-
# Mock model response for demo purposes
|
| 7 |
response = f"Echo: {user_input}"
|
| 8 |
history.append({"role": "user", "content": user_input})
|
| 9 |
history.append({"role": "assistant", "content": response})
|
| 10 |
return history
|
| 11 |
|
| 12 |
-
#
|
| 13 |
def create_chat_interface():
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
gr.Markdown("# Chatbot Interface")
|
| 16 |
-
|
| 17 |
# Chat display
|
| 18 |
chatbot_component = gr.Chatbot(type="messages", label="Chat History", height=500)
|
| 19 |
-
|
| 20 |
-
# Input and button container
|
| 21 |
-
with gr.Row(elem_id="input_container"):
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# Custom CSS to position the send button inside the input box
|
| 30 |
demo.css = """
|
| 31 |
#input_container {
|
| 32 |
display: flex;
|
| 33 |
justify-content: center;
|
|
|
|
| 34 |
margin-top: 10px;
|
| 35 |
-
}
|
| 36 |
-
#input_with_button {
|
| 37 |
-
position: relative;
|
| 38 |
width: 100%;
|
| 39 |
max-width: 600px;
|
|
|
|
| 40 |
}
|
| 41 |
#user_input {
|
| 42 |
-
|
| 43 |
-
padding-left: 40px; /*
|
| 44 |
border-radius: 8px;
|
| 45 |
border: 1px solid #ccc;
|
| 46 |
height: 40px;
|
|
@@ -48,8 +44,7 @@ def create_chat_interface():
|
|
| 48 |
}
|
| 49 |
#send_button {
|
| 50 |
position: absolute;
|
| 51 |
-
left:
|
| 52 |
-
top: 5px;
|
| 53 |
width: 30px;
|
| 54 |
height: 30px;
|
| 55 |
border-radius: 50%;
|
|
@@ -65,8 +60,8 @@ def create_chat_interface():
|
|
| 65 |
background-color: #0056b3;
|
| 66 |
}
|
| 67 |
"""
|
| 68 |
-
|
| 69 |
-
# Link button click to
|
| 70 |
send_button.click(
|
| 71 |
chatbot,
|
| 72 |
inputs=[user_input, chatbot_component],
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
# Function to generate chatbot responses
|
| 4 |
def chatbot(user_input, history):
|
|
|
|
| 5 |
response = f"Echo: {user_input}"
|
| 6 |
history.append({"role": "user", "content": user_input})
|
| 7 |
history.append({"role": "assistant", "content": response})
|
| 8 |
return history
|
| 9 |
|
| 10 |
+
# Create the chat interface
|
| 11 |
def create_chat_interface():
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
gr.Markdown("# Chatbot Interface")
|
| 14 |
+
|
| 15 |
# Chat display
|
| 16 |
chatbot_component = gr.Chatbot(type="messages", label="Chat History", height=500)
|
| 17 |
+
|
| 18 |
+
# Input and send button container
|
| 19 |
+
with gr.Row(elem_id="input_container", equal_height=True):
|
| 20 |
+
# Send button inside input box
|
| 21 |
+
user_input = gr.Textbox(
|
| 22 |
+
placeholder="Type your message here...", label=None, elem_id="user_input"
|
| 23 |
+
)
|
| 24 |
+
send_button = gr.Button("📤", elem_id="send_button")
|
| 25 |
+
|
| 26 |
+
# Custom CSS to style the layout
|
|
|
|
| 27 |
demo.css = """
|
| 28 |
#input_container {
|
| 29 |
display: flex;
|
| 30 |
justify-content: center;
|
| 31 |
+
align-items: center;
|
| 32 |
margin-top: 10px;
|
|
|
|
|
|
|
|
|
|
| 33 |
width: 100%;
|
| 34 |
max-width: 600px;
|
| 35 |
+
position: relative;
|
| 36 |
}
|
| 37 |
#user_input {
|
| 38 |
+
flex-grow: 1;
|
| 39 |
+
padding-left: 40px; /* Add space for the send button */
|
| 40 |
border-radius: 8px;
|
| 41 |
border: 1px solid #ccc;
|
| 42 |
height: 40px;
|
|
|
|
| 44 |
}
|
| 45 |
#send_button {
|
| 46 |
position: absolute;
|
| 47 |
+
left: 10px;
|
|
|
|
| 48 |
width: 30px;
|
| 49 |
height: 30px;
|
| 50 |
border-radius: 50%;
|
|
|
|
| 60 |
background-color: #0056b3;
|
| 61 |
}
|
| 62 |
"""
|
| 63 |
+
|
| 64 |
+
# Link button click to chatbot function
|
| 65 |
send_button.click(
|
| 66 |
chatbot,
|
| 67 |
inputs=[user_input, chatbot_component],
|