Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
|
| 6 |
+
# Pollinations API URL
|
| 7 |
+
POLLINATIONS_API_URL = "https://api.pollinations.ai/generate"
|
| 8 |
+
|
| 9 |
+
# Funktion zum Abrufen von Game Assets von Pollinations
|
| 10 |
+
def generate_game_asset(description):
|
| 11 |
+
payload = {
|
| 12 |
+
"prompt": description, # Beschreibung des Game Assets
|
| 13 |
+
"width": 512, # Bildbreite
|
| 14 |
+
"height": 512 # Bildhöhe
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
response = requests.post(POLLINATIONS_API_URL, json=payload)
|
| 18 |
+
|
| 19 |
+
if response.status_code == 200:
|
| 20 |
+
img_data = response.content
|
| 21 |
+
img = Image.open(BytesIO(img_data))
|
| 22 |
+
return img
|
| 23 |
+
else:
|
| 24 |
+
return "Fehler bei der Asset-Erstellung"
|
| 25 |
+
|
| 26 |
+
# Gradio Interface
|
| 27 |
+
def create_gradio_interface():
|
| 28 |
+
# Erstelle das Gradio Interface mit Textinput und Bildausgabe
|
| 29 |
+
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown("# Game Asset Generator")
|
| 31 |
+
gr.Markdown("Generiere Game Assets durch Eingabe einer Beschreibung.")
|
| 32 |
+
|
| 33 |
+
description_input = gr.Textbox(label="Asset Beschreibung", placeholder="z.B. Ein magischer Wald")
|
| 34 |
+
output_image = gr.Image(type="pil", label="Generiertes Game Asset")
|
| 35 |
+
|
| 36 |
+
description_input.submit(generate_game_asset, inputs=description_input, outputs=output_image)
|
| 37 |
+
|
| 38 |
+
return demo
|
| 39 |
+
|
| 40 |
+
# Starte das Gradio Interface
|
| 41 |
+
demo = create_gradio_interface()
|
| 42 |
+
demo.launch()
|