tony-assi-lora / app.py
tonyassi's picture
Update app.py
a83bcf0 verified
import gradio as gr
import random
import requests
import io
from PIL import Image
import os
from huggingface_hub import InferenceClient
client = InferenceClient("tonyassi/tony-assi-lora-1", token=os.environ.get('TOKEN'))
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.content
def generate(prompt):
"""
image_bytes = query({
"inputs": "Tony Assi style " + prompt,
"parameters" : { "negative_prompt": "ugly, deformed, bad quality",
"seed": random.randint(0,9999999)}
})
image = Image.open(io.BytesIO(image_bytes))
"""
# output is a PIL.Image object
image = client.text_to_image(prompt=prompt, negative_prompt="ugly, deformed, bad quality")
return image
theme = gr.themes.Base(
primary_hue="gray",
secondary_hue="gray",
neutral_hue="gray",
font=['Helvetica', 'ui-sans-serif', 'system-ui', 'sans-serif'],
).set(
button_large_text_weight='400',
input_background_fill='#ffffff',
#input_border_width='*block_border_width',
#button_primary_background_fill='#ffffff',
#button_border_width='*block_border_width',
)
with gr.Blocks(theme=theme) as demo:
img = gr.Image(show_label=False, type='pil')
textbox = gr.Textbox(show_label=False, placeholder='type your prompt in here')
button = gr.Button("generate", variant="primary")
gr.Examples(
[["Kendall Jenner wearing a black mesh outfit with puffy black sleeves"], ["Hunter Schafer wearing a mint green mesh outfit with puffy sleeves"], ["Eva Mendes wearing clear vinyl outfit"]],
textbox,
img,
generate,
cache_examples=True,
)
button.click(fn=generate, inputs=textbox, outputs=img)
textbox.submit(fn=generate, inputs=textbox, outputs=img)
demo.launch()