freddyaboulton HF Staff commited on
Commit
2deb8f4
·
verified ·
1 Parent(s): 2cdead4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client, handle_file
3
+
4
+ captioning_space = Client("gokaygokay/SD3-Long-Captioner")
5
+ llm_space = Client("hysts/zephyr-7b")
6
+
7
+ SYSTEM_PROMPT = """
8
+ You are helpful assistant that gives the best compliments to people.
9
+ You will be given a caption of someone's headshot.
10
+ Based on that caption, provide a one sentence compliment to the person in the image.
11
+ Make sure you compliment the person in the image and not any objects or scenery.
12
+ Do not include any hashtags in your compliment.
13
+
14
+ Good Example:
15
+
16
+ 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.
17
+ Compliment: Your smile is as bright as a lighthouse, lighting up the world around you. 🌟
18
+
19
+ Good Example:
20
+
21
+ 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.
22
+ Compliment: You are the epitome of elegance and grace, with a style that is as timeless as your beauty. 💃🎩
23
+
24
+ Bad Example:
25
+
26
+ 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.
27
+ Compliment: You are standing in front of a lovely lighthouse!
28
+
29
+ Bad Example:
30
+
31
+ 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.
32
+ 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)
33
+ """
34
+
35
+ def generate_compliment(img):
36
+ caption = captioning_space.predict(handle_file(img), api_name="/create_captions_rich")
37
+ for partial_response in llm_space.submit(
38
+ message=f"Caption: {caption}\nCompliment: ",
39
+ system_prompt=SYSTEM_PROMPT,
40
+ max_new_tokens=1024,
41
+ temperature=0.7,
42
+ top_p=0.95,
43
+ top_k=50,
44
+ repetition_penalty=1,
45
+ api_name="/chat"):
46
+ yield ("# " + partial_response).replace("\"", "")
47
+
48
+
49
+ with gr.Blocks() as demo:
50
+ gr.Markdown(
51
+ f"<h1 style='text-align: center; margin-bottom: 1rem'>ComplimentBot💖</h1>"
52
+ )
53
+ img = gr.Image(type="filepath")
54
+ markdown = gr.Markdown()
55
+ img.upload(generate_compliment, [img], [markdown])
56
+ img.clear(lambda: "", None, markdown)
57
+
58
+ demo.launch()