KingNish commited on
Commit
1d60322
1 Parent(s): c2d1d44

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +46 -46
chatbot.py CHANGED
@@ -148,6 +148,51 @@ def video_gen(prompt):
148
  client = Client("KingNish/Instant-Video")
149
  return client.predict(prompt, api_name="/instant_video")
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  image_extensions = Image.registered_extensions()
152
  video_extensions = ("avi", "mp4", "mov", "mkv", "flv", "wmv", "mjpeg", "wav", "gif", "webm", "m4v", "3gp")
153
 
@@ -157,53 +202,8 @@ client_mixtral = InferenceClient("NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO")
157
  client_llama = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
158
  client_mistral_nemo = InferenceClient("mistralai/Mistral-Nemo-Instruct-2407")
159
 
 
160
  def model_inference(user_prompt, chat_history):
161
-
162
- @spaces.GPU(duration=60, queue=False)
163
- def qwen_inference(user_prompt, chat_history):
164
- images = []
165
- text_input = user_prompt["text"]
166
-
167
- # Handle multiple image uploads
168
- if user_prompt["files"]:
169
- images.extend(user_prompt["files"])
170
- else:
171
- for hist in chat_history:
172
- if type(hist[0]) == tuple:
173
- images.extend(hist[0])
174
-
175
- # System Prompt (Similar to LLaVA)
176
- SYSTEM_PROMPT = "You are OpenGPT 4o, an exceptionally capable and versatile AI assistant made by KingNish. Your task is to fulfill users query in best possible way. You are provided with image, videos and 3d structures as input with question your task is to give best possible detailed results to user according to their query. Reply the question asked by user properly and best possible way."
177
-
178
- messages = [{"role": "system", "content": SYSTEM_PROMPT}]
179
-
180
- for image in images:
181
- if image.endswith(video_extensions):
182
- messages.append({
183
- "role": "user",
184
- "content": [
185
- {"type": "video", "video": image},
186
- ]
187
- })
188
-
189
- if image.endswith(tuple([i for i, f in image_extensions.items()])):
190
- messages.append({
191
- "role": "user",
192
- "content": [
193
- {"type": "image", "image": image},
194
- ]
195
- })
196
-
197
- # Add user text input
198
- messages.append({
199
- "role": "user",
200
- "content": [
201
- {"type": "text", "text": text_input}
202
- ]
203
- })
204
-
205
- return messages
206
-
207
  if user_prompt["files"]:
208
  messages = qwen_inference(user_prompt, chat_history)
209
  text = processor.apply_chat_template(
 
148
  client = Client("KingNish/Instant-Video")
149
  return client.predict(prompt, api_name="/instant_video")
150
 
151
+ @spaces.GPU(duration=60, queue=False)
152
+ def qwen_inference(user_prompt, chat_history):
153
+ images = []
154
+ text_input = user_prompt["text"]
155
+
156
+ # Handle multiple image uploads
157
+ if user_prompt["files"]:
158
+ images.extend(user_prompt["files"])
159
+ else:
160
+ for hist in chat_history:
161
+ if type(hist[0]) == tuple:
162
+ images.extend(hist[0])
163
+
164
+ # System Prompt (Similar to LLaVA)
165
+ SYSTEM_PROMPT = "You are OpenGPT 4o, an exceptionally capable and versatile AI assistant made by KingNish. Your task is to fulfill users query in best possible way. You are provided with image, videos and 3d structures as input with question your task is to give best possible detailed results to user according to their query. Reply the question asked by user properly and best possible way."
166
+
167
+ messages = [{"role": "system", "content": SYSTEM_PROMPT}]
168
+
169
+ for image in images:
170
+ if image.endswith(video_extensions):
171
+ messages.append({
172
+ "role": "user",
173
+ "content": [
174
+ {"type": "video", "video": image},
175
+ ]
176
+ })
177
+
178
+ if image.endswith(tuple([i for i, f in image_extensions.items()])):
179
+ messages.append({
180
+ "role": "user",
181
+ "content": [
182
+ {"type": "image", "image": image},
183
+ ]
184
+ })
185
+
186
+ # Add user text input
187
+ messages.append({
188
+ "role": "user",
189
+ "content": [
190
+ {"type": "text", "text": text_input}
191
+ ]
192
+ })
193
+
194
+ return messages
195
+
196
  image_extensions = Image.registered_extensions()
197
  video_extensions = ("avi", "mp4", "mov", "mkv", "flv", "wmv", "mjpeg", "wav", "gif", "webm", "m4v", "3gp")
198
 
 
202
  client_llama = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
203
  client_mistral_nemo = InferenceClient("mistralai/Mistral-Nemo-Instruct-2407")
204
 
205
+ @spaces.GPU(duration=60, queue=False)
206
  def model_inference(user_prompt, chat_history):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  if user_prompt["files"]:
208
  messages = qwen_inference(user_prompt, chat_history)
209
  text = processor.apply_chat_template(