File size: 2,113 Bytes
dbe116c
 
 
6615678
e2457f2
 
 
 
 
 
 
dbe116c
6615678
 
 
dbe116c
 
6615678
dbe116c
 
 
 
6615678
dbe116c
6615678
 
 
dbe116c
e2457f2
 
dbe116c
 
 
 
 
 
 
 
e2457f2
dbe116c
 
 
 
 
6615678
dbe116c
 
 
6615678
dbe116c
 
 
 
 
 
 
 
 
6615678
dbe116c
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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"<img src='{message}' width='200px'><br>"
        else:
            display += f"<b>{sender}:</b> {message}<br>"
    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()