File size: 1,698 Bytes
be405ee 68c1454 be405ee 2047d5a be405ee 2047d5a be405ee e5c7021 be405ee 8264ed9 be405ee 3e5f8f0 be405ee 68c1454 8264ed9 2047d5a 8264ed9 be405ee 2047d5a be405ee 2047d5a be405ee 2047d5a |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import gradio as gr
import requests
import os
from PIL import Image
from io import BytesIO
from tqdm import tqdm
import time
# Defining the repository information and the trigger word
repo = "artificialguybr/StudioGhibli.Redmond-V2"
trigger_word = "Studio Ghibli, StdGBRedmAF"
def generate_image(prompt):
api_url = f"https://api-inference.huggingface.co/models/{repo}"
#token = os.getenv("API_TOKEN") # Uncomment and use your Hugging Face API token
headers = {
#"Authorization": f"Bearer {token}"
}
full_prompt = f"{prompt} {trigger_word}"
payload = {
"inputs": full_prompt,
"parameters": {
"negative_prompt": "bad art, ugly, watermark, deformed",
"num_inference_steps": 30,
"scheduler": "DPMSolverMultistepScheduler"
},
}
error_count = 0
pbar = tqdm(total=None, desc="Loading model")
while True:
response = requests.post(api_url, headers=headers, json=payload)
if response.status_code == 200:
return Image.open(BytesIO(response.content)) # Changed to match the first code
elif response.status_code == 503:
time.sleep(1)
pbar.update(1)
elif response.status_code == 500 and error_count < 5:
time.sleep(1)
error_count += 1
else:
raise Exception(f"API Error: {response.status_code}")
iface = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(lines=2, placeholder="Type your prompt here..."),
outputs="image",
title="Studio Ghibli Image Generator V2",
description="Enter a text prompt to generate an image in the style of Studio Ghibli."
)
iface.launch() |