Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import io, os | |
| from PIL import Image | |
| api_key = os.environ.get("HF_API_KEY") | |
| API_URL = "https://api-inference.huggingface.co/models/multimodalart/liminal-spaces" | |
| headers = {"Authorization": f"Bearer {api_key}"} | |
| # Function to query the model | |
| def query_image(inputs): | |
| payload = {"inputs": inputs} | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| image_bytes = response.content | |
| image = Image.open(io.BytesIO(image_bytes)) | |
| return image, inputs | |
| # Define Gradio Blocks UI | |
| with gr.Blocks(theme="nevreal/blues") as demo: | |
| gr.Markdown("# liminal spaces") | |
| with gr.Row(): | |
| gr.Markdown("model by [multimodalart](https://huggingface.co/multimodalart) this spces by [nevreal](https://huggingface.co/nevreal)") | |
| with gr.Row(): | |
| prompt = gr.Textbox(label="Enter your prompt", value="Astronaut riding a horse", lines=2) | |
| submit_button = gr.Button("Generate Image") | |
| with gr.Column(): | |
| output_image = gr.Image(label="Generated Image") | |
| # Add examples | |
| examples = gr.Examples( | |
| examples=[ | |
| "A person in a bustling cafe as a liminal space", | |
| "The city of Paris as a liminal space" | |
| ], | |
| inputs=prompt, | |
| ) | |
| # Link button action to function | |
| submit_button.click(fn=query_image, inputs=prompt, outputs=output_image) | |
| # Launch the web UI | |
| demo.launch() | |