Spaces:
Running
Running
Upload 2 files
Browse files- app (1).py +38 -0
- requirements.txt +6 -0
app (1).py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
import PIL
|
6 |
+
|
7 |
+
API_URL = "https://api-inference.huggingface.co/models/Linaqruf/animagine-xl"
|
8 |
+
headers = {"Authorization": "Bearer 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"}
|
9 |
+
|
10 |
+
def generate_image(prompt):
|
11 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
12 |
+
|
13 |
+
if response.status_code == 200:
|
14 |
+
image_bytes = response.content
|
15 |
+
|
16 |
+
try:
|
17 |
+
image = Image.open(io.BytesIO(image_bytes))
|
18 |
+
return image
|
19 |
+
except PIL.UnidentifiedImageError as e:
|
20 |
+
return None
|
21 |
+
else:
|
22 |
+
return None
|
23 |
+
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=generate_image,
|
26 |
+
inputs="text",
|
27 |
+
outputs="image",
|
28 |
+
title="🌄 Prompt to Image Generator 🌄",
|
29 |
+
description="Generate stunning images from your prompts using an AI model.",
|
30 |
+
layout="wide",
|
31 |
+
theme="huggingface",
|
32 |
+
examples=[
|
33 |
+
["A surreal painting of a floating city at sunset"],
|
34 |
+
["An abstract landscape with vibrant colors and geometric shapes"]
|
35 |
+
]
|
36 |
+
)
|
37 |
+
iface.launch(share=True, server_port=8888)
|
38 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
requests
|
4 |
+
gradio
|
5 |
+
pillow
|
6 |
+
requires.io
|