Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ model_id = "llava-hf/llava-interleave-qwen-0.5b-hf"
|
|
17 |
|
18 |
processor = LlavaProcessor.from_pretrained(model_id)
|
19 |
|
20 |
-
model = LlavaForConditionalGeneration.from_pretrained(model_id
|
21 |
model.to("cpu")
|
22 |
|
23 |
|
@@ -82,7 +82,6 @@ client_llama = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
|
82 |
# Define the main chat function
|
83 |
def respond(message, history):
|
84 |
func_caller = []
|
85 |
-
vqa = ""
|
86 |
|
87 |
user_prompt = message
|
88 |
# Handle image processing
|
@@ -107,7 +106,7 @@ def respond(message, history):
|
|
107 |
]
|
108 |
|
109 |
message_text = message["text"]
|
110 |
-
func_caller.append({"role": "user", "content": f'[SYSTEM]You are a helpful assistant. You have access to the following functions: \n {str(functions_metadata)}\n\nTo use these functions respond with:\n<functioncall> {{ "name": "function_name", "arguments": {{ "arg_1": "value_1", "arg_1": "value_1", ... }} }} </functioncall> [USER] {message_text}
|
111 |
|
112 |
response = client_gemma.chat_completion(func_caller, max_tokens=150)
|
113 |
response = str(response)
|
@@ -134,7 +133,7 @@ def respond(message, history):
|
|
134 |
for msg in history:
|
135 |
messages += f"\n<|im_start|>user\n{str(msg[0])}<|im_end|>"
|
136 |
messages += f"\n<|im_start|>assistant\n{str(msg[1])}<|im_end|>"
|
137 |
-
messages+=f"\n<|im_start|>user\n{message_text}
|
138 |
stream = client_mixtral.text_generation(messages, max_new_tokens=2000, do_sample=True, stream=True, details=True, return_full_text=False)
|
139 |
output = ""
|
140 |
for response in stream:
|
@@ -146,7 +145,7 @@ def respond(message, history):
|
|
146 |
gr.Info("Generating Image, Please wait 10 sec...")
|
147 |
seed = random.randint(1, 99999)
|
148 |
query = query.replace(" ", "%20")
|
149 |
-
image = f"![](https://image.pollinations.ai/prompt/{query}?seed={seed})"
|
150 |
yield image
|
151 |
time.sleep(8)
|
152 |
gr.Info("We are going to Update Our Image Generation Engine to more powerful ones in Next Update. ThankYou")
|
@@ -167,7 +166,7 @@ def respond(message, history):
|
|
167 |
for msg in history:
|
168 |
messages += f"\n<|start_header_id|>user\n{str(msg[0])}<|end_header_id|>"
|
169 |
messages += f"\n<|start_header_id|>assistant\n{str(msg[1])}<|end_header_id|>"
|
170 |
-
messages+=f"\n<|start_header_id|>user\n{message_text}
|
171 |
stream = client_llama.text_generation(messages, max_new_tokens=2000, do_sample=True, stream=True, details=True, return_full_text=False)
|
172 |
output = ""
|
173 |
for response in stream:
|
@@ -179,7 +178,7 @@ def respond(message, history):
|
|
179 |
for msg in history:
|
180 |
messages += f"\n<|start_header_id|>user\n{str(msg[0])}<|end_header_id|>"
|
181 |
messages += f"\n<|start_header_id|>assistant\n{str(msg[1])}<|end_header_id|>"
|
182 |
-
messages+=f"\n<|start_header_id|>user\n{message_text}
|
183 |
stream = client_llama.text_generation(messages, max_new_tokens=2000, do_sample=True, stream=True, details=True, return_full_text=False)
|
184 |
output = ""
|
185 |
for response in stream:
|
|
|
17 |
|
18 |
processor = LlavaProcessor.from_pretrained(model_id)
|
19 |
|
20 |
+
model = LlavaForConditionalGeneration.from_pretrained(model_id)
|
21 |
model.to("cpu")
|
22 |
|
23 |
|
|
|
82 |
# Define the main chat function
|
83 |
def respond(message, history):
|
84 |
func_caller = []
|
|
|
85 |
|
86 |
user_prompt = message
|
87 |
# Handle image processing
|
|
|
106 |
]
|
107 |
|
108 |
message_text = message["text"]
|
109 |
+
func_caller.append({"role": "user", "content": f'[SYSTEM]You are a helpful assistant. You have access to the following functions: \n {str(functions_metadata)}\n\nTo use these functions respond with:\n<functioncall> {{ "name": "function_name", "arguments": {{ "arg_1": "value_1", "arg_1": "value_1", ... }} }} </functioncall> [USER] {message_text}'})
|
110 |
|
111 |
response = client_gemma.chat_completion(func_caller, max_tokens=150)
|
112 |
response = str(response)
|
|
|
133 |
for msg in history:
|
134 |
messages += f"\n<|im_start|>user\n{str(msg[0])}<|im_end|>"
|
135 |
messages += f"\n<|im_start|>assistant\n{str(msg[1])}<|im_end|>"
|
136 |
+
messages+=f"\n<|im_start|>user\n{message_text}<|im_end|>\n<|im_start|>web_result\n{web2}<|im_end|>\n<|im_start|>assistant\n"
|
137 |
stream = client_mixtral.text_generation(messages, max_new_tokens=2000, do_sample=True, stream=True, details=True, return_full_text=False)
|
138 |
output = ""
|
139 |
for response in stream:
|
|
|
145 |
gr.Info("Generating Image, Please wait 10 sec...")
|
146 |
seed = random.randint(1, 99999)
|
147 |
query = query.replace(" ", "%20")
|
148 |
+
image = f"![](https://image.pollinations.ai/prompt/{message_text}{query}?seed={seed})"
|
149 |
yield image
|
150 |
time.sleep(8)
|
151 |
gr.Info("We are going to Update Our Image Generation Engine to more powerful ones in Next Update. ThankYou")
|
|
|
166 |
for msg in history:
|
167 |
messages += f"\n<|start_header_id|>user\n{str(msg[0])}<|end_header_id|>"
|
168 |
messages += f"\n<|start_header_id|>assistant\n{str(msg[1])}<|end_header_id|>"
|
169 |
+
messages+=f"\n<|start_header_id|>user\n{message_text}<|end_header_id|>\n<|start_header_id|>assistant\n"
|
170 |
stream = client_llama.text_generation(messages, max_new_tokens=2000, do_sample=True, stream=True, details=True, return_full_text=False)
|
171 |
output = ""
|
172 |
for response in stream:
|
|
|
178 |
for msg in history:
|
179 |
messages += f"\n<|start_header_id|>user\n{str(msg[0])}<|end_header_id|>"
|
180 |
messages += f"\n<|start_header_id|>assistant\n{str(msg[1])}<|end_header_id|>"
|
181 |
+
messages+=f"\n<|start_header_id|>user\n{message_text}<|end_header_id|>\n<|start_header_id|>assistant\n"
|
182 |
stream = client_llama.text_generation(messages, max_new_tokens=2000, do_sample=True, stream=True, details=True, return_full_text=False)
|
183 |
output = ""
|
184 |
for response in stream:
|