Download app.py from apapiu/transformer_diffusion_gpu_api: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/apapiu/transformer_diffusion_gpu_api/resolve/main/app.py
- Command line
-
hf download hf://spaces/apapiu/transformer_diffusion_gpu_api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/apapiu/transformer_diffusion_gpu_api/resolve/main/app.py
1.17 kB
| import gradio as gr | |
| import requests | |
| from PIL import Image | |
| from io import BytesIO | |
| import os | |
| runpod_id = os.environ['RUNPOD_ID'] | |
| token_id = os.environ['AUTH_TOKEN'] | |
| #url = f'https://{runpod_id}-8000.proxy.runpod.net/generate-image/' | |
| url = "http://my-tld-app-container-dns.eastus.azurecontainer.io/generate-image/" | |
| def generate_image_from_text(prompt, class_guidance): | |
| headers = { | |
| 'Authorization': f'Bearer {token_id}' | |
| } | |
| data = { | |
| "prompt": prompt, | |
| "class_guidance": class_guidance, | |
| "seed": 11, | |
| "num_imgs": 1, | |
| "img_size": 32 | |
| } | |
| response = requests.post(url, json=data, headers=headers) | |
| if response.status_code == 200: | |
| image = Image.open(BytesIO(response.content)) | |
| else: | |
| print("Failed to fetch image:", response.status_code, response.text) | |
| return image | |
| # Define the Gradio interface | |
| iface = gr.Interface( | |
| fn=generate_image_from_text, # The function to generate the image | |
| inputs=["text", "slider"], | |
| outputs="image", | |
| title="Text-to-Image Generator", | |
| description="Enter a text prompt to generate an image." | |
| ) | |
| # Launch the app | |
| iface.launch() |