File size: 915 Bytes
807a5e1
fe4b707
 
 
 
 
 
 
 
 
 
 
 
807a5e1
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()