File size: 1,196 Bytes
5e5fd54
72398d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e5fd54
 
72398d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr
import requests
from io import BytesIO
from PIL import Image

HARDCODED_URL = "https://images.unsplash.com/photo-1682687220204-276355c19923?ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2940&q=80"  # Replace with your desired URL

def get_image_from_hardcoded_url(prompt):
    """
    Loads and returns an image from a hardcoded URL.
    The prompt is ignored in this version.
    """
    try:
        response = requests.get(HARDCODED_URL, stream=True)
        response.raise_for_status()
        image = Image.open(BytesIO(response.content))
        return image
    except requests.exceptions.RequestException as e:
        return f"Error fetching image: {e}"
    except Exception as e:
        return f"Error processing image: {e}"


iface = gr.Interface(
    fn=get_image_from_hardcoded_url,
    inputs=gr.Textbox(lines=2, label="Enter a Prompt (Ignored)"),
    outputs=gr.Image(label="Fetched Image"),
    title="Image Fetcher (Hardcoded URL)",
    description="Enter a prompt which will be ignored. The app will then fetch the image from a hardcoded URL and display it."
)

if __name__ == "__main__":
    iface.launch()