Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
def image_mod(image):
|
| 4 |
print(image)
|
| 5 |
return f"<img src='file={image}'>"
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
def append_image_in_markdown(string_output: str) -> str:
|
| 3 |
+
"""
|
| 4 |
+
Append an image in markdown format to a string if an image is found in the string.
|
| 5 |
+
:param string_output: (str) the string to append the image to
|
| 6 |
+
:return: (str) the string with the image appended in markdown format
|
| 7 |
+
"""
|
| 8 |
+
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+\.jpg|\.png|\.jpeg|\.gif', string_output)
|
| 9 |
+
for url in urls:
|
| 10 |
+
url = url.rstrip('.')
|
| 11 |
+
if url.lower().endswith(('.jpg', '.jpeg', '.png', '.gif')):
|
| 12 |
+
return string_output + f'\n\n'
|
| 13 |
+
return string_output
|
| 14 |
def image_mod(image):
|
| 15 |
print(image)
|
| 16 |
return f"<img src='file={image}'>"
|