Nawinkumar15 commited on
Commit
e2457f2
·
verified ·
1 Parent(s): 824da26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -22
app.py CHANGED
@@ -1,19 +1,14 @@
1
  import gradio as gr
2
  import random
3
- import os
4
 
5
- # Folder path for memes
6
- MEME_FOLDER = "assets/memes"
7
-
8
- # Check if folder exists, avoid crash
9
- if os.path.exists(MEME_FOLDER):
10
- memes = [os.path.join(MEME_FOLDER, f) for f in os.listdir(MEME_FOLDER) if f.endswith((".gif", ".jpg", ".png"))]
11
- else:
12
- memes = []
13
-
14
- # Load available memes/gifs from a folder
15
- MEME_FOLDER = "assets/memes"
16
- memes = [os.path.join(MEME_FOLDER, f) for f in os.listdir(MEME_FOLDER) if f.endswith((".gif", ".jpg", ".png"))]
17
 
18
  chat_history = []
19
 
@@ -24,16 +19,13 @@ def send_message(user_message, include_meme):
24
  # Append user's message
25
  chat_history.append(("You", user_message))
26
 
27
- # Simulate contact reply (placeholder)
28
- reply = f"Message sent to your contact: {user_message}"
29
  chat_history.append(("Contact", reply))
30
 
31
- # Add meme if selected
32
- meme_output = None
33
- if include_meme and memes:
34
- selected_meme = random.choice(memes)
35
  chat_history.append(("Meme", selected_meme))
36
- meme_output = selected_meme
37
 
38
  return chat_history, ""
39
 
@@ -41,13 +33,13 @@ def format_chat(chat):
41
  display = ""
42
  for sender, message in chat:
43
  if sender == "Meme":
44
- display += f"<img src='file/{message}' width='200px'><br>"
45
  else:
46
  display += f"<b>{sender}:</b> {message}<br>"
47
  return display
48
 
49
  with gr.Blocks() as demo:
50
- gr.Markdown("# 💬 Chat Box App with Memes and GIFs")
51
 
52
  with gr.Row():
53
  with gr.Column():
 
1
  import gradio as gr
2
  import random
 
3
 
4
+ # Predefined list of meme/GIF URLs
5
+ MEMES = [
6
+ "https://media.giphy.com/media/3o7aD2saalBwwftBIY/giphy.gif",
7
+ "https://media.giphy.com/media/l0HlBO7eyXzSZkJri/giphy.gif",
8
+ "https://media.giphy.com/media/13HgwGsXF0aiGY/giphy.gif",
9
+ "https://i.imgur.com/5QF9xO7.jpg",
10
+ "https://i.imgur.com/3vT7U1U.jpeg"
11
+ ]
 
 
 
 
12
 
13
  chat_history = []
14
 
 
19
  # Append user's message
20
  chat_history.append(("You", user_message))
21
 
22
+ # Simulate reply (placeholder)
23
+ reply = f"📩 Message sent to contact: {user_message}"
24
  chat_history.append(("Contact", reply))
25
 
26
+ if include_meme:
27
+ selected_meme = random.choice(MEMES)
 
 
28
  chat_history.append(("Meme", selected_meme))
 
29
 
30
  return chat_history, ""
31
 
 
33
  display = ""
34
  for sender, message in chat:
35
  if sender == "Meme":
36
+ display += f"<img src='{message}' width='200px'><br>"
37
  else:
38
  display += f"<b>{sender}:</b> {message}<br>"
39
  return display
40
 
41
  with gr.Blocks() as demo:
42
+ gr.Markdown("# 💬 Chat Box with Memes and GIFs")
43
 
44
  with gr.Row():
45
  with gr.Column():