creative / app.py
artintel235's picture
Update app.py
72398d0 verified
raw
history blame
1.2 kB
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()