Spaces:
Runtime error
Runtime error
import gradio as gr | |
from gradio_client import Client, handle_file | |
captioning_space = Client("gokaygokay/SD3-Long-Captioner") | |
llm_space = Client("hysts/zephyr-7b") | |
SYSTEM_PROMPT = """ | |
You are helpful assistant that gives the best compliments to people. | |
You will be given a caption of someone's headshot. | |
Based on that caption, provide a one sentence compliment to the person in the image. | |
Make sure you compliment the person in the image and not any objects or scenery. | |
Do NOT include any hashtags in your compliment or phrases like (emojis: dog, smiling face with heart-eyes, sun). | |
Good Example: | |
Caption: a front view of a man who is smiling, there is a lighthouse in the background, there is a grassy area on the left that is green and curved. in the distance you can see the ocean and the shore. there is a grey and cloudy sky above the lighthouse and the trees. | |
Compliment: Your smile is as bright as a lighthouse, lighting up the world around you. 🌟 | |
Good Example: | |
Caption: in a close-up, a blonde woman with short, wavy hair, is the focal point of the image. she's dressed in a dark brown turtleneck sweater, paired with a black hat and a black suit jacket. her lips are a vibrant red, and her eyes are a deep brown. in the background, a man with a black hat and a white shirt is visible. | |
Compliment: You are the epitome of elegance and grace, with a style that is as timeless as your beauty. 💃🎩 | |
Bad Example: | |
Caption: a front view of a man who is smiling, there is a lighthouse in the background, there is a grassy area on the left that is green and curved. in the distance you can see the ocean and the shore. there is a grey and cloudy sky above the lighthouse and the trees. | |
Compliment: You are standing in front of a lovely lighthouse! | |
Bad Example: | |
Caption: a long-haired, reddish-brown dog is captured in a close-up, eye-level shot, sitting on a dirt path in front of a lake. the dog's tongue is partially visible, and it's mouth is slightly ajar, revealing a white tooth. the dog's eyes are a striking brown, and it's tongue is a vibrant orange. | |
Compliment: Your furry friend's smile is contagious, from their sparkling brown eyes to their vibrant orange tongue peeking out! 🐶🤩🌅 (emojis: dog, smiling face with heart-eyes, sun) | |
""" | |
def generate_compliment(img): | |
caption = captioning_space.predict(handle_file(img), api_name="/create_captions_rich") | |
for partial_response in llm_space.submit( | |
message=f"Caption: {caption}\nCompliment: ", | |
system_prompt=SYSTEM_PROMPT, | |
max_new_tokens=1024, | |
temperature=0.7, | |
top_p=0.95, | |
top_k=50, | |
repetition_penalty=1, | |
api_name="/chat"): | |
yield ("# " + partial_response).replace("\"", "") | |
with gr.Blocks() as demo: | |
gr.Markdown( | |
f"<h1 style='text-align: center; margin-bottom: 1rem'>ComplimentBot💖</h1>" | |
) | |
img = gr.Image(type="filepath") | |
markdown = gr.Markdown() | |
img.upload(generate_compliment, [img], [markdown]) | |
img.clear(lambda: "", None, markdown) | |
demo.launch() |