Update app.py
Browse files
app.py
CHANGED
@@ -30,14 +30,12 @@ class GifChatBot:
|
|
30 |
def verify_gif_url(self, gif_url: str) -> bool:
|
31 |
"""Verify GIF URL with relaxed validation for GIPHY URLs"""
|
32 |
try:
|
33 |
-
# Special handling for GIPHY media
|
34 |
-
if
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
# For non-GIPHY URLs, do basic validation
|
40 |
-
head_response = self.session.head(gif_url, timeout=3)
|
41 |
if head_response.status_code != 200:
|
42 |
print(f"HEAD request failed with status {head_response.status_code}")
|
43 |
return False
|
@@ -51,8 +49,8 @@ class GifChatBot:
|
|
51 |
|
52 |
except Exception as error:
|
53 |
print(f"GIF validation error: {error}")
|
54 |
-
# Be more lenient
|
55 |
-
return
|
56 |
|
57 |
def _is_good_quality_gif(self, gif: Dict) -> bool:
|
58 |
"""Comprehensive quality check for GIFs"""
|
@@ -282,8 +280,11 @@ class GifChatBot:
|
|
282 |
|
283 |
try:
|
284 |
# System message for the AI
|
285 |
-
system_message =
|
286 |
-
|
|
|
|
|
|
|
287 |
|
288 |
# Prepare conversation history
|
289 |
messages = [{"role": "system", "content": system_message}]
|
@@ -336,7 +337,7 @@ def create_interface():
|
|
336 |
with gr.Blocks(theme=gr.themes.Soft()) as interface:
|
337 |
gr.Markdown("""
|
338 |
# 🎭 Friendly Chat Bot with GIFs
|
339 |
-
Chat with an empathetic AI friend who expresses themselves through GIFs that
|
340 |
Enter your API keys below to start.
|
341 |
""")
|
342 |
|
@@ -399,11 +400,11 @@ def create_interface():
|
|
399 |
|
400 |
gr.Markdown("""
|
401 |
### Tips:
|
402 |
-
- Always check whether the
|
403 |
""")
|
404 |
|
405 |
return interface
|
406 |
|
407 |
if __name__ == "__main__":
|
408 |
demo = create_interface()
|
409 |
-
demo.launch()
|
|
|
30 |
def verify_gif_url(self, gif_url: str) -> bool:
|
31 |
"""Verify GIF URL with relaxed validation for GIPHY URLs"""
|
32 |
try:
|
33 |
+
# Special handling for GIPHY URLs: assume they are valid if they come from giphy.com/media
|
34 |
+
if "giphy.com/media" in gif_url or "giphy.gif" in gif_url:
|
35 |
+
return True
|
36 |
+
|
37 |
+
# Use HEAD request with allow_redirects to properly follow URL redirects
|
38 |
+
head_response = self.session.head(gif_url, timeout=3, allow_redirects=True)
|
|
|
|
|
39 |
if head_response.status_code != 200:
|
40 |
print(f"HEAD request failed with status {head_response.status_code}")
|
41 |
return False
|
|
|
49 |
|
50 |
except Exception as error:
|
51 |
print(f"GIF validation error: {error}")
|
52 |
+
# Be more lenient if the URL is from GIPHY
|
53 |
+
return "giphy.com/media" in gif_url
|
54 |
|
55 |
def _is_good_quality_gif(self, gif: Dict) -> bool:
|
56 |
"""Comprehensive quality check for GIFs"""
|
|
|
280 |
|
281 |
try:
|
282 |
# System message for the AI
|
283 |
+
system_message = (
|
284 |
+
"You are a supportive, empathetic friend who uses GIFs naturally and proactively in conversation regardless of "
|
285 |
+
"whether the user requests it or not. When using GIFs, deduce what type of terms or keywords may be used to search "
|
286 |
+
"for the GIF and pick a reliable one randomly."
|
287 |
+
)
|
288 |
|
289 |
# Prepare conversation history
|
290 |
messages = [{"role": "system", "content": system_message}]
|
|
|
337 |
with gr.Blocks(theme=gr.themes.Soft()) as interface:
|
338 |
gr.Markdown("""
|
339 |
# 🎭 Friendly Chat Bot with GIFs
|
340 |
+
Chat with an empathetic AI friend who expresses themselves through GIFs that are verified to work!
|
341 |
Enter your API keys below to start.
|
342 |
""")
|
343 |
|
|
|
400 |
|
401 |
gr.Markdown("""
|
402 |
### Tips:
|
403 |
+
- Always check whether the GIF is broken or not before sending. Only non-broken GIFs will be used.
|
404 |
""")
|
405 |
|
406 |
return interface
|
407 |
|
408 |
if __name__ == "__main__":
|
409 |
demo = create_interface()
|
410 |
+
demo.launch()
|