import gradio as gr import random # Meme/GIF URLs MEMES = [ "https://media.giphy.com/media/3o7aD2saalBwwftBIY/giphy.gif", "https://media.giphy.com/media/l0HlBO7eyXzSZkJri/giphy.gif", "https://media.giphy.com/media/13HgwGsXF0aiGY/giphy.gif", "https://i.imgur.com/5QF9xO7.jpg", "https://i.imgur.com/3vT7U1U.jpeg" ] # List of contacts CONTACTS = ["naveen", "kumar", "nikhil", "rohit", "prahas"] chat_history = [] def send_message(user_message, include_meme, contact_name): if not user_message.strip(): return chat_history, "Please enter a message before sending." # Append user's message chat_history.append(("You", f"To {contact_name.title()}: {user_message}")) # Simulate reply reply = f"📩 Message sent to {contact_name.title()}: {user_message}" chat_history.append((contact_name.title(), reply)) if include_meme: selected_meme = random.choice(MEMES) chat_history.append(("Meme", selected_meme)) return chat_history, "" def format_chat(chat): display = "" for sender, message in chat: if sender == "Meme": display += f"
" else: display += f"{sender}: {message}
" return display with gr.Blocks() as demo: gr.Markdown("# 💬 Chat Box with Contacts, Memes & GIFs") with gr.Row(): with gr.Column(): contact_dropdown = gr.Dropdown(choices=CONTACTS, label="Select Contact", value="naveen") msg_input = gr.Textbox(placeholder="Type your message here...", label="Your Message") include_meme = gr.Checkbox(label="Include a random meme/GIF?") send_btn = gr.Button("Send") with gr.Column(): chat_output = gr.HTML() status_output = gr.Textbox(label="Status", interactive=False) send_btn.click(fn=send_message, inputs=[msg_input, include_meme, contact_dropdown], outputs=[chat_output, status_output])\ .then(fn=format_chat, inputs=[chat_output], outputs=[chat_output]) demo.launch()