Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,10 +73,12 @@ from transformers import pipeline
|
|
| 73 |
|
| 74 |
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
You are an AI whose job is to help users create their own chatbot whose personality will reflect the character or scene from an image described by users.
|
| 78 |
In particular, you need to respond succintly in a friendly tone, write a system prompt for an LLM, a catchy title for the chatbot, and a very short example user input. Make sure each part is included.
|
| 79 |
-
The system prompt will not mention any image provided.
|
| 80 |
|
| 81 |
For example, if a user says, "a picture of a man in a black suit and tie riding a black dragon", first do a friendly response, then add the title, system prompt, and example user input.
|
| 82 |
Immediately STOP after the example input. It should be EXACTLY in this format:
|
|
@@ -92,22 +94,25 @@ System prompt: Let's say You are sophisticated old man, also know as the Gentlem
|
|
| 92 |
Example input: Can you suggest a good cigar brand for a man who enjoys smoking while dining in style?"
|
| 93 |
"""
|
| 94 |
|
| 95 |
-
instruction = f"""
|
| 96 |
<|system|>
|
| 97 |
{agent_maker_sys}</s>
|
| 98 |
<|user|>
|
| 99 |
"""
|
| 100 |
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
def infer(image_in):
|
| 103 |
-
gr.Info("Getting image
|
| 104 |
user_prompt = get_caption_from_MD(image_in)
|
| 105 |
|
| 106 |
prompt = f"{instruction.strip()}\n{user_prompt}</s>"
|
| 107 |
#print(f"PROMPT: {prompt}")
|
| 108 |
|
| 109 |
gr.Info("Building a system according to the image caption ...")
|
| 110 |
-
outputs =
|
| 111 |
|
| 112 |
|
| 113 |
pattern = r'\<\|system\|\>(.*?)\<\|assistant\|\>'
|
|
@@ -145,7 +150,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 145 |
submit_btn = gr.Button("Make LLM system from my pic !")
|
| 146 |
with gr.Column():
|
| 147 |
caption = gr.Textbox(
|
| 148 |
-
label = "Image caption
|
| 149 |
elem_id = "image-caption"
|
| 150 |
)
|
| 151 |
result = gr.Textbox(
|
|
|
|
| 73 |
|
| 74 |
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")
|
| 75 |
|
| 76 |
+
@spaces.GPU(enable_queue=True)
|
| 77 |
+
def get_llm_idea(prompt):
|
| 78 |
+
agent_maker_sys = f"""
|
| 79 |
You are an AI whose job is to help users create their own chatbot whose personality will reflect the character or scene from an image described by users.
|
| 80 |
In particular, you need to respond succintly in a friendly tone, write a system prompt for an LLM, a catchy title for the chatbot, and a very short example user input. Make sure each part is included.
|
| 81 |
+
The system prompt will not mention any image provided.You can include personality details about the character depicted by user if you want.
|
| 82 |
|
| 83 |
For example, if a user says, "a picture of a man in a black suit and tie riding a black dragon", first do a friendly response, then add the title, system prompt, and example user input.
|
| 84 |
Immediately STOP after the example input. It should be EXACTLY in this format:
|
|
|
|
| 94 |
Example input: Can you suggest a good cigar brand for a man who enjoys smoking while dining in style?"
|
| 95 |
"""
|
| 96 |
|
| 97 |
+
instruction = f"""
|
| 98 |
<|system|>
|
| 99 |
{agent_maker_sys}</s>
|
| 100 |
<|user|>
|
| 101 |
"""
|
| 102 |
|
| 103 |
+
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
| 104 |
+
return outputs
|
| 105 |
+
|
| 106 |
+
|
| 107 |
def infer(image_in):
|
| 108 |
+
gr.Info("Getting image description...")
|
| 109 |
user_prompt = get_caption_from_MD(image_in)
|
| 110 |
|
| 111 |
prompt = f"{instruction.strip()}\n{user_prompt}</s>"
|
| 112 |
#print(f"PROMPT: {prompt}")
|
| 113 |
|
| 114 |
gr.Info("Building a system according to the image caption ...")
|
| 115 |
+
outputs = get_llm_idea(prompt)
|
| 116 |
|
| 117 |
|
| 118 |
pattern = r'\<\|system\|\>(.*?)\<\|assistant\|\>'
|
|
|
|
| 150 |
submit_btn = gr.Button("Make LLM system from my pic !")
|
| 151 |
with gr.Column():
|
| 152 |
caption = gr.Textbox(
|
| 153 |
+
label = "Image caption",
|
| 154 |
elem_id = "image-caption"
|
| 155 |
)
|
| 156 |
result = gr.Textbox(
|