File size: 1,156 Bytes
fca1b98
93a61c7
 
3ca1d70
fca1b98
0a66490
93a61c7
fca1b98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7b5b75
 
0a66490
e1da499
15367d5
 
 
 
 
 
 
 
a70a8f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gradio as gr
import requests
import io
import os
from PIL import Image

API_URL = "https://api-inference.huggingface.co/models/Kvikontent/kviimager2.0"
api_key = os.environ.get('API_KEY')
headers = {"Authorization": f"Bearer {api_key}"}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.content

def generate_image_from_prompt(prompt_text):
    image_bytes = query({"inputs": prompt_text})
    generated_image = Image.open(io.BytesIO(image_bytes))
    return generated_image

title = "KVIImager 2.0 Demo 🎨"
description = "This app uses Hugging Face AI model to generate an image based on the provided text prompt πŸ–ΌοΈ."

input_prompt = gr.Textbox(label="Enter Prompt πŸ“", placeholder="E.g. 'A peaceful garden with a small cottage'")
output_generated_image = gr.Image(label="Generated Image")

with gr.Blocks(theme=gr.themes.Soft()) as app:
    caption = "Generate Image"
    iface = gr.Interface(
        generate_image_from_prompt,
        inputs=input_prompt, 
        outputs=output_generated_image, 
        title=title,
        description=description
    )
    iface.launch()