ImgTest / app.py
CognitiveScience's picture
Update app.py
fe4b707 verified
raw
history blame contribute delete
915 Bytes
import gradio as gr
def append_image_in_markdown(string_output: str) -> str:
"""
Append an image in markdown format to a string if an image is found in the string.
:param string_output: (str) the string to append the image to
:return: (str) the string with the image appended in markdown format
"""
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+\.jpg|\.png|\.jpeg|\.gif', string_output)
for url in urls:
url = url.rstrip('.')
if url.lower().endswith(('.jpg', '.jpeg', '.png', '.gif')):
return string_output + f'\n\n![Image]({url})'
return string_output
def image_mod(image):
print(image)
return f"<img src='file={image}'>"
with gr.Blocks() as demo:
img = gr.Image(type='filepath')
with gr.Row():
htm1 = gr.HTML()
gr.Button().click(image_mod,img, [htm1])
demo.launch()