File size: 2,581 Bytes
66a500b
da28892
a180f58
7685695
401f757
02458f6
80621e1
da28892
 
d516faa
c7f0abc
 
 
 
 
02458f6
071c36e
c7f0abc
d516faa
 
da28892
f5b81b8
da28892
 
 
 
 
 
 
 
 
 
 
401f757
 
 
80621e1
da28892
66a500b
401f757
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
import gradio as gr
from huggingface_hub import InferenceClient
import os

client = InferenceClient("EvanZhouDev/open-genmoji", token=os.getenv("HUGGINGFACE_API_TOKEN"))
llm = InferenceClient("Qwen/Qwen2.5-72B-Instruct")

# Define the process function that takes a text prompt and returns an image
def process(prompt):
    print(prompt)
    messages = [
    	{ "role": "system", "content": "You are helping create a prompt for a Emoji generation image model. An emoji must be easily interpreted when small so details must be exaggerated to be clear. Your goal is to use descriptions to achieve this.\n\nYou will receive a user description, and you must rephrase it to consist of short phrases separated by periods, adding detail to everything the user provides.\n\nAdd describe the color of all parts or components of the emoji. Unless otherwise specified by the user, do not describe people. Do not describe the background of the image. Your output should be in the format:\n\n```\nemoji of {description}. {addon phrases}. 3D lighting. no cast shadows.\n```\n\nThe description should be a 1 sentence of your interpretation of the emoji.\nThen, you may choose to add addon phrases. You must use the following in the given scenarios:\n\n- \"cute.\": If generating anything that's not an object, and also not a human\n- \"enlarged head in cartoon style.\": ONLY animals\n- \"head is turned towards viewer.\": ONLY humans or animals\n- \"detailed texture.\": ONLY objects\n\nFurther addon phrases may be added to ensure the clarity of the emoji." },
    	{ "role": "user", "content": prompt }
    ]

    completion = client.chat_completion(messages, max_tokens=100)
    response = completion.get("choices")[0].get("message").get("content").replace("```", "").replace("\n", "")

    print(response)
    image = client.text_to_image(response)
    return image

# Create a Gradio Blocks app
with gr.Blocks() as demo:
    # Create a Textbox for the input prompt
    prompt_input = gr.Textbox(label="Enter a prompt")
    # Create an Image component for the output image
    image_output = gr.Image(label="Generated Image")
    # Create a Button to trigger the image generation
    generate_button = gr.Button("Generate Image")
    
    # Define the event listener for the button click
    generate_button.click(fn=process, inputs=prompt_input, outputs=image_output)
    
    # Define the event listener for the Enter key press
    prompt_input.submit(fn=process, inputs=prompt_input, outputs=image_output)

# Launch the interface
if __name__ == "__main__":
    demo.launch(show_error=True)