Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445461 unmodified line48495051525354559 unmodified lines6566676869707172import gradio as grfrom transformers import pipeline# Function to generate text based on the modeldef chatbot(user_input, history):# Mock model response for demo purposesresponse = f"Echo: {user_input}"history.append({"role": "user", "content": user_input})history.append({"role": "assistant", "content": response})return history# Main interface layoutdef create_chat_interface():with gr.Blocks() as demo:gr.Markdown("# Chatbot Interface")# Chat displaychatbot_component = gr.Chatbot(type="messages", label="Chat History", height=500)# Input and button containerwith gr.Row(elem_id="input_container"):# Input field with the button insidewith gr.Box(elem_id="input_with_button"):send_button = gr.Button("📤", elem_id="send_button")user_input = gr.Textbox(placeholder="Type your message here...", label=None, lines=1, elem_id="user_input")# Custom CSS to position the send button inside the input boxdemo.css = """#input_container {display: flex;justify-content: center;margin-top: 10px;}#input_with_button {position: relative;width: 100%;max-width: 600px;}#user_input {width: 100%;padding-left: 40px; /* To make space for the button */border-radius: 8px;border: 1px solid #ccc;height: 40px;1 unmodified line}#send_button {position: absolute;left: 5px;top: 5px;width: 30px;height: 30px;border-radius: 50%;9 unmodified linesbackground-color: #0056b3;}"""# Link button click to the chatbot functionsend_button.click(chatbot,inputs=[user_input, chatbot_component],1234567891011121314151617181920212223242526272829303132333435363738394041421 unmodified line444546474849509 unmodified lines6061626364656667import gradio as gr# Function to generate chatbot responsesdef chatbot(user_input, history):response = f"Echo: {user_input}"history.append({"role": "user", "content": user_input})history.append({"role": "assistant", "content": response})return history# Create the chat interfacedef create_chat_interface():with gr.Blocks() as demo:gr.Markdown("# Chatbot Interface")# Chat displaychatbot_component = gr.Chatbot(type="messages", label="Chat History", height=500)# Input and send button containerwith gr.Row(elem_id="input_container", equal_height=True):# Send button inside input boxuser_input = gr.Textbox(placeholder="Type your message here...", label=None, elem_id="user_input")send_button = gr.Button("📤", elem_id="send_button")# Custom CSS to style the layoutdemo.css = """#input_container {display: flex;justify-content: center;align-items: center;margin-top: 10px;width: 100%;max-width: 600px;position: relative;}#user_input {flex-grow: 1;padding-left: 40px; /* Add space for the send button */border-radius: 8px;border: 1px solid #ccc;height: 40px;1 unmodified line}#send_button {position: absolute;left: 10px;width: 30px;height: 30px;border-radius: 50%;9 unmodified linesbackground-color: #0056b3;}"""# Link button click to chatbot functionsend_button.click(chatbot,inputs=[user_input, chatbot_component],
app.py+20-25