Spaces:
Sleeping
Sleeping
Update application/chat_inference.py
Browse files
application/chat_inference.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
from application.utils.chat_completion_api import ChatCompletionAPI
|
2 |
from config import Response,pipeline_dict,convs_dict
|
3 |
import os
|
|
|
4 |
|
5 |
class ChatInference:
|
6 |
def __init__(self):
|
7 |
self.chatCompletionAPI = ChatCompletionAPI()
|
|
|
8 |
|
9 |
def validate(self,data,user):
|
10 |
try:
|
@@ -30,12 +32,19 @@ class ChatInference:
|
|
30 |
top_p = max(0.1, min(data.get('top_p', 0.9), 1))
|
31 |
system = data.get('system_prompt','You are a helpful and harmless AI assistant. You are xylaria made by sk md saad amin. You should think step-by-step')
|
32 |
convId = data['convId']
|
33 |
-
|
|
|
34 |
if(len(convs_dict[user][convId]['messages'])==1):
|
35 |
if system:
|
36 |
convs_dict[user][convId]['messages'].insert(0,{"role":"system", "content": system})
|
37 |
convs_dict[user]['metadata'].insert(0,{"convId": convId, "title": prompt[:23]})
|
38 |
convs_dict[user][convId]['title'] = prompt[:30]
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
if(pipeline[model]['type'] == 'image-text-to-text'):
|
40 |
convs_dict[user][convId]['messages'].append({"role": "user", "content": [{"type":"text","text":prompt}]})
|
41 |
else:
|
|
|
1 |
from application.utils.chat_completion_api import ChatCompletionAPI
|
2 |
from config import Response,pipeline_dict,convs_dict
|
3 |
import os
|
4 |
+
from application.utils.image_captioning import ImageCaptioning
|
5 |
|
6 |
class ChatInference:
|
7 |
def __init__(self):
|
8 |
self.chatCompletionAPI = ChatCompletionAPI()
|
9 |
+
self.image_captioning = ImageCaptioning()
|
10 |
|
11 |
def validate(self,data,user):
|
12 |
try:
|
|
|
32 |
top_p = max(0.1, min(data.get('top_p', 0.9), 1))
|
33 |
system = data.get('system_prompt','You are a helpful and harmless AI assistant. You are xylaria made by sk md saad amin. You should think step-by-step')
|
34 |
convId = data['convId']
|
35 |
+
image = data.get('image')
|
36 |
+
|
37 |
if(len(convs_dict[user][convId]['messages'])==1):
|
38 |
if system:
|
39 |
convs_dict[user][convId]['messages'].insert(0,{"role":"system", "content": system})
|
40 |
convs_dict[user]['metadata'].insert(0,{"convId": convId, "title": prompt[:23]})
|
41 |
convs_dict[user][convId]['title'] = prompt[:30]
|
42 |
+
|
43 |
+
if image:
|
44 |
+
caption = self.image_captioning.generate_caption(image)
|
45 |
+
prompt = f"{caption}\n\n{prompt}"
|
46 |
+
|
47 |
+
|
48 |
if(pipeline[model]['type'] == 'image-text-to-text'):
|
49 |
convs_dict[user][convId]['messages'].append({"role": "user", "content": [{"type":"text","text":prompt}]})
|
50 |
else:
|