Update app.py
Browse files
app.py
CHANGED
@@ -99,11 +99,13 @@ def respond(message, history):
|
|
99 |
image_extensions = tuple([ex for ex, f in image_extensions.items()])
|
100 |
|
101 |
if image.endswith(video_extensions):
|
|
|
102 |
image = sample_frames(image)
|
103 |
image_tokens = "<image>" * int(len(image))
|
104 |
prompt = f"<|im_start|>user {image_tokens}\n{user_prompt}<|im_end|><|im_start|>assistant"
|
105 |
|
106 |
elif image.endswith(image_extensions):
|
|
|
107 |
image = Image.open(image).convert("RGB")
|
108 |
prompt = f"<|im_start|>user <image>\n{user_prompt}<|im_end|><|im_start|>assistant"
|
109 |
|
@@ -114,6 +116,7 @@ def respond(message, history):
|
|
114 |
|
115 |
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
116 |
thread.start()
|
|
|
117 |
|
118 |
buffer = ""
|
119 |
for new_text in streamer:
|
@@ -174,16 +177,6 @@ def respond(message, history):
|
|
174 |
gr.Info("We are going to Update Our Image Generation Engine to more powerful ones in Next Update. ThankYou")
|
175 |
elif json_data["name"] == "image_qna":
|
176 |
messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You are provide with both images and captions and Your task is to answer of user with help of caption provided. Answer in human style and show emotions.<|end_header_id|>"
|
177 |
-
for msg in history:
|
178 |
-
messages += f"\n<|start_header_id|>user\n{str(msg[0])}<|end_header_id|>"
|
179 |
-
messages += f"\n<|start_header_id|>assistant\n{str(msg[1])}<|end_header_id|>"
|
180 |
-
messages+=f"\n<|start_header_id|>user\n{message_text} {vqa}<|end_header_id|>\n<|start_header_id|>assistant\n"
|
181 |
-
stream = client_llama.text_generation(messages, max_new_tokens=2000, do_sample=True, stream=True, details=True, return_full_text=False)
|
182 |
-
output = ""
|
183 |
-
for response in stream:
|
184 |
-
if not response.token.text == "<|eot_id|>":
|
185 |
-
output += response.token.text
|
186 |
-
yield output
|
187 |
else:
|
188 |
messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You answers users query like human friend. You are also Expert in every field and also learn and try to answer from contexts related to previous question. Try your best to give best response possible to user. You also try to show emotions using Emojis and reply like human, use short forms, friendly tone and emotions.<|end_header_id|>"
|
189 |
for msg in history:
|
|
|
99 |
image_extensions = tuple([ex for ex, f in image_extensions.items()])
|
100 |
|
101 |
if image.endswith(video_extensions):
|
102 |
+
gr.Info(f"Analyzing {video_extensions} file")
|
103 |
image = sample_frames(image)
|
104 |
image_tokens = "<image>" * int(len(image))
|
105 |
prompt = f"<|im_start|>user {image_tokens}\n{user_prompt}<|im_end|><|im_start|>assistant"
|
106 |
|
107 |
elif image.endswith(image_extensions):
|
108 |
+
gr.Info("Analyzing image")
|
109 |
image = Image.open(image).convert("RGB")
|
110 |
prompt = f"<|im_start|>user <image>\n{user_prompt}<|im_end|><|im_start|>assistant"
|
111 |
|
|
|
116 |
|
117 |
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
118 |
thread.start()
|
119 |
+
gr.Info("Generating output")
|
120 |
|
121 |
buffer = ""
|
122 |
for new_text in streamer:
|
|
|
177 |
gr.Info("We are going to Update Our Image Generation Engine to more powerful ones in Next Update. ThankYou")
|
178 |
elif json_data["name"] == "image_qna":
|
179 |
messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You are provide with both images and captions and Your task is to answer of user with help of caption provided. Answer in human style and show emotions.<|end_header_id|>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
else:
|
181 |
messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You answers users query like human friend. You are also Expert in every field and also learn and try to answer from contexts related to previous question. Try your best to give best response possible to user. You also try to show emotions using Emojis and reply like human, use short forms, friendly tone and emotions.<|end_header_id|>"
|
182 |
for msg in history:
|