Spaces:
Runtime error
Runtime error
zhizhi-aiservice:0.1.2
Browse files- main.py +174 -255
- models.py +11 -18
- requirements.txt +20 -30
main.py
CHANGED
@@ -7,57 +7,41 @@
|
|
7 |
#pip install torch ###for torch
|
8 |
#pip install sentencepiece ###for AutoTokenizer
|
9 |
#pip install -U cos-python-sdk-v5 ###腾讯云对象存储SDK(COS-SDK)
|
|
|
10 |
|
11 |
-
from typing import Optional
|
12 |
-
from fastapi import FastAPI, Header
|
13 |
-
from
|
14 |
-
#
|
15 |
-
import
|
16 |
-
from
|
17 |
-
from
|
18 |
-
from openai import OpenAI
|
19 |
|
20 |
-
from qcloud_cos import CosConfig, CosS3Client
|
21 |
-
import sys, os, logging
|
22 |
-
import urllib.parse as urlparse
|
23 |
-
import json, requests
|
24 |
-
|
25 |
-
# class Conversation:
|
26 |
-
# def __init__(self, openai_client: OpenAI, prompt, num_of_round):
|
27 |
-
# self.openai_client = openai_client
|
28 |
-
# self.prompt = prompt
|
29 |
-
# self.num_of_round = num_of_round
|
30 |
-
# self.messages = []
|
31 |
-
# self.messages.append({"role": "system", "content": self.prompt})
|
32 |
-
|
33 |
-
# def ask(self, question):
|
34 |
-
# message = ''
|
35 |
-
# num_of_tokens = 0
|
36 |
-
# try:
|
37 |
-
# self.messages.append( {"role": "user", "content": question})
|
38 |
-
# chat_completion = self.openai_client.chat.completions.create(
|
39 |
-
# model="gpt-3.5-turbo",
|
40 |
-
# messages=self.messages,
|
41 |
-
# temperature=0.5,
|
42 |
-
# max_tokens=2048,
|
43 |
-
# top_p=1,
|
44 |
-
# )
|
45 |
-
# message = chat_completion.choices[0].message.content
|
46 |
-
# # num_of_tokens = chat_completion.usage.total_tokens
|
47 |
-
# self.messages.append({"role": "assistant", "content": message})
|
48 |
-
|
49 |
-
# except Exception as e:
|
50 |
-
# print(e)
|
51 |
-
# return e
|
52 |
-
|
53 |
-
# if len(self.messages) > self.num_of_round*2 + 1:
|
54 |
-
# del self.messages[1:3]
|
55 |
-
# return message, num_of_tokens
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
|
|
58 |
app = FastAPI()
|
59 |
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
cos_secret_id = os.environ['COS_SECRET_ID']
|
62 |
cos_secret_key = os.environ['COS_SECRET_KEY']
|
63 |
cos_region = 'ap-shanghai'
|
@@ -66,35 +50,77 @@ token = None
|
|
66 |
scheme = 'https'
|
67 |
config = CosConfig(Region=cos_region, SecretId=cos_secret_id, SecretKey=cos_secret_key, Token=token, Scheme=scheme)
|
68 |
client = CosS3Client(config)
|
69 |
-
logging.info(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
)
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
try:
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
95 |
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
#try:
|
100 |
# ai_model_ez_preprocessor = AutoTokenizer.from_pretrained("./opus-mt-en-zh")
|
@@ -110,29 +136,29 @@ except Exception as e:
|
|
110 |
#except Exception as e:
|
111 |
# print(e)
|
112 |
|
113 |
-
def bird_classifier(image_file: str) -> str:
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
|
133 |
|
134 |
-
|
135 |
-
|
136 |
|
137 |
# def text_en_zh(text_en: str) -> str:
|
138 |
# text_zh = ""
|
@@ -146,125 +172,47 @@ def bird_classifier(image_file: str) -> str:
|
|
146 |
|
147 |
# return text_zh
|
148 |
|
149 |
-
# Route to upload a file
|
150 |
-
# @app.post("/uploadfile/")
|
151 |
-
# async def create_upload_file(file: UploadFile):
|
152 |
-
# contents: bytes = await file.read()
|
153 |
-
# contents_len = len(contents)
|
154 |
-
# file_name = file.filename
|
155 |
-
# server_file_name = f"server-{file_name}"
|
156 |
-
# with open(server_file_name,"wb") as server_file:
|
157 |
-
# server_file.write(contents)
|
158 |
-
|
159 |
-
# logging.info(f"{file_name} is received and saved as {server_file_name}.")
|
160 |
-
|
161 |
-
# bird_classification = bird_classifier(server_file_name)
|
162 |
-
|
163 |
-
# # if bird_classification != "":
|
164 |
-
# # bird_classification = "the species of bird is " + bird_classification
|
165 |
-
# # bird_classification = text_en_zh(bird_classification)
|
166 |
-
|
167 |
-
# logging.info(f"AI feedback: {bird_classification}.")
|
168 |
-
|
169 |
-
# return {"filename": server_file_name, "AI feedback": bird_classification}
|
170 |
|
171 |
-
# Route to
|
172 |
-
@app.
|
173 |
-
def
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
code2Session = f"http://api.weixin.qq.com/sns/jscode2session?appid={item.appid}&secret={item.secret}&js_code={item.js_code}&grant_type={item.grant_type}"
|
178 |
-
logging.info(code2Session)
|
179 |
|
180 |
-
|
181 |
-
json_response = response.json()
|
182 |
-
logging.info(json_response)
|
183 |
|
184 |
-
|
|
|
|
|
|
|
185 |
|
186 |
-
#
|
187 |
-
@app.post("/items/")
|
188 |
-
async def create_item(item: ItemUploaded, x_wx_openid: Optional[str]=Header(None)):
|
189 |
-
logging.info("create_item")
|
190 |
-
logging.info(item)
|
191 |
-
logging.info(x_wx_openid)
|
192 |
-
|
193 |
-
if x_wx_openid is None:
|
194 |
-
x_wx_openid = ""
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
prompt = """你是一个鸟类学家,用中文回答关于鸟类的问题。你的回答需要满足以下要求:
|
216 |
-
1. 你的回答必须是中文
|
217 |
-
2. 回答限制在100个字以内"""
|
218 |
-
|
219 |
-
messages = []
|
220 |
-
messages.append({"role": "system", "content": prompt})
|
221 |
-
question = f"鸟类的英文名是{bird_classification},它的中文名是什么?有什么样的习性?"
|
222 |
-
messages.append( {"role": "user", "content": question})
|
223 |
-
chat_completion = openai_client.chat.completions.create(
|
224 |
-
model="gpt-3.5-turbo",
|
225 |
-
messages=messages,
|
226 |
-
temperature=0.5,
|
227 |
-
max_tokens=2048,
|
228 |
-
top_p=1,
|
229 |
-
)
|
230 |
-
response = chat_completion.choices[0].message.content
|
231 |
-
logging.info(f"chatgpt feedback: {response}.\n")
|
232 |
-
|
233 |
-
except Exception as e:
|
234 |
-
logging.error(e)
|
235 |
-
else:
|
236 |
-
bird_classification = "不是image类型,暂不能识别"
|
237 |
-
|
238 |
-
logging.info(f"AI feedback: {bird_classification}.\n")
|
239 |
-
|
240 |
-
historyfile = itemToJsonFile(ItemInHistory(history_id = historyid,union_id = x_wx_openid,
|
241 |
-
item_fileurl = item.item_fileurl,item_mediatype = item.item_mediatype,
|
242 |
-
upload_datetime = item.upload_datetime,ai_feedback = bird_classification))
|
243 |
-
|
244 |
-
response = client.upload_file(
|
245 |
-
Bucket = cos_bucket,
|
246 |
-
LocalFilePath=historyfile,
|
247 |
-
Key=f'{x_wx_openid}/history/{historyfile}',
|
248 |
-
PartSize=1,
|
249 |
-
MAXThread=10,
|
250 |
-
EnableMD5=False
|
251 |
-
)
|
252 |
-
logging.info(response['ETag'])
|
253 |
-
|
254 |
-
|
255 |
-
return {"filename": historyfile, "AI feedback": bird_classification}
|
256 |
-
|
257 |
-
# Route to list all items uploaded by a specific user by unionid
|
258 |
-
# @app.get("/items/{user_unionid}")
|
259 |
-
# def list_items(user_unionid: str) -> dict[str, list[ItemInHistory]]:
|
260 |
-
# logging.info("list_items")
|
261 |
-
# logging.info(user_unionid)
|
262 |
|
263 |
# items: list[ItemInHistory] = []
|
264 |
|
265 |
# response = client.list_objects(
|
266 |
# Bucket=cos_bucket,
|
267 |
-
# Prefix=f'{
|
268 |
# )
|
269 |
|
270 |
# logging.info(response['Contents'])
|
@@ -281,62 +229,33 @@ async def create_item(item: ItemUploaded, x_wx_openid: Optional[str]=Header(None
|
|
281 |
# item = itemFromJsonFile(localfile)
|
282 |
# items.append(item)
|
283 |
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
return {"items": items}
|
314 |
-
|
315 |
-
|
316 |
-
def itemFromJsonFile(jsonfile: str) -> ItemInHistory:
|
317 |
-
f = open(jsonfile, 'r')
|
318 |
-
content = f.read()
|
319 |
-
a = json.loads(content)
|
320 |
-
f.close()
|
321 |
-
return ItemInHistory(history_id = a['history_id'],union_id = a['union_id'],
|
322 |
-
item_fileurl = a['item_fileurl'],item_mediatype = a["item_mediatype"],
|
323 |
-
upload_datetime = a["upload_datetime"],ai_feedback = a['ai_feedback'])
|
324 |
-
|
325 |
-
|
326 |
-
def itemToJsonFile(item: ItemInHistory):
|
327 |
-
history_json = {
|
328 |
-
"history_id": item.history_id,
|
329 |
-
"union_id": item.union_id,
|
330 |
-
"item_fileurl": item.item_fileurl,
|
331 |
-
"item_mediatype": item.item_mediatype,
|
332 |
-
"upload_datetime": item.upload_datetime,
|
333 |
-
"ai_feedback": item.ai_feedback
|
334 |
-
}
|
335 |
-
b = json.dumps(history_json)
|
336 |
-
historyfile = f'{item.history_id}.json'
|
337 |
-
f = open(historyfile, 'w')
|
338 |
-
f.write(b)
|
339 |
-
f.close()
|
340 |
-
|
341 |
-
return historyfile
|
342 |
|
|
|
7 |
#pip install torch ###for torch
|
8 |
#pip install sentencepiece ###for AutoTokenizer
|
9 |
#pip install -U cos-python-sdk-v5 ###腾讯云对象存储SDK(COS-SDK)
|
10 |
+
#pip install -q -U google-generativeai
|
11 |
|
12 |
+
# from typing import Optional
|
13 |
+
# from fastapi import FastAPI, Header
|
14 |
+
# #from transformers import pipeline, EfficientNetImageProcessor, EfficientNetForImageClassification, AutoTokenizer, AutoModelForSeq2SeqLM
|
15 |
+
# import torch
|
16 |
+
# from transformers import EfficientNetImageProcessor, EfficientNetForImageClassification, pipeline
|
17 |
+
# from models import ItemInHistory, ItemUploaded, ServiceLoginInfo
|
18 |
+
# from openai import OpenAI
|
|
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# import sys, os, logging
|
22 |
+
# import json, requests
|
23 |
+
|
24 |
+
|
25 |
+
from fastapi import FastAPI
|
26 |
+
import sys, logging, os
|
27 |
+
from models import Item2AI, AI2Item
|
28 |
+
import google.generativeai as genai
|
29 |
+
import urllib.parse as urlparse
|
30 |
+
from qcloud_cos import CosConfig, CosS3Client
|
31 |
+
from PIL import Image
|
32 |
|
33 |
+
# init app and logging
|
34 |
app = FastAPI()
|
35 |
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
|
36 |
|
37 |
+
# load google gemini models
|
38 |
+
genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))
|
39 |
+
gemini_pro = genai.GenerativeModel('gemini-pro')
|
40 |
+
logging.info("google gemini-pro model loaded successfully.")
|
41 |
+
gemini_pro_vision = genai.GenerativeModel('gemini-pro-vision')
|
42 |
+
logging.info("google gemini-pro-vision model loaded successfully.")
|
43 |
+
|
44 |
+
# init tencent cos
|
45 |
cos_secret_id = os.environ['COS_SECRET_ID']
|
46 |
cos_secret_key = os.environ['COS_SECRET_KEY']
|
47 |
cos_region = 'ap-shanghai'
|
|
|
50 |
scheme = 'https'
|
51 |
config = CosConfig(Region=cos_region, SecretId=cos_secret_id, SecretKey=cos_secret_key, Token=token, Scheme=scheme)
|
52 |
client = CosS3Client(config)
|
53 |
+
logging.info(f"tencent cos init succeeded.")
|
54 |
+
|
55 |
+
# Route to create an item
|
56 |
+
@app.post("/firstturn/")
|
57 |
+
async def ai_first_turn(item: Item2AI):
|
58 |
+
logging.info("ai_first_turn...")
|
59 |
+
logging.info("item:", item)
|
60 |
|
61 |
+
# response = gemini_pro.generate_content("What is the meaning of life?")
|
62 |
+
# logging.info(response.text)
|
63 |
|
64 |
+
url = urlparse.urlparse(item.item_fileurl)
|
65 |
+
key = url[2][1::]
|
66 |
+
bucket = url[1].split('.')[1]
|
67 |
+
contentfile = key.split('/')[1]
|
68 |
+
historyid = contentfile.split('.')[0]
|
69 |
+
|
70 |
+
response = client.get_object(
|
71 |
+
Bucket = bucket,
|
72 |
+
Key = key
|
73 |
+
)
|
74 |
+
response['Body'].get_stream_to_file(contentfile)
|
75 |
|
76 |
+
ai2item = AI2Item(
|
77 |
+
upload_id = item.upload_id,
|
78 |
+
union_id = item.union_id,
|
79 |
+
item_fileurl = item.item_fileurl,
|
80 |
+
item_mediatype = item.item_mediatype,
|
81 |
+
upload_datetime = item.upload_datetime,
|
82 |
+
ai_feedback = ""
|
83 |
)
|
84 |
+
if item.item_mediatype == "image":
|
85 |
+
# Opening the image using PIL
|
86 |
+
img = Image.open(contentfile)
|
87 |
+
logging.info(f"image file {contentfile} is opened.")
|
88 |
+
response = gemini_pro_vision.generate_content(["Describe this picture in Chinese with plenty of details.", img])
|
89 |
+
ai2item.ai_feedback = response.text
|
90 |
+
else:
|
91 |
+
ai2item.ai_feedback = "不是image类型,暂不能识别"
|
92 |
+
|
93 |
+
logging.info(ai2item)
|
94 |
+
|
95 |
+
return(ai2item)
|
96 |
+
|
97 |
|
98 |
+
# try:
|
99 |
+
# ai_model_bc_preprocessor = EfficientNetImageProcessor.from_pretrained("./birds-classifier-efficientnetb2")
|
100 |
+
# ai_model_bc_model = EfficientNetForImageClassification.from_pretrained("./birds-classifier-efficientnetb2")
|
101 |
+
# logging.info(f"local model dennisjooo/Birds-Classifier-EfficientNetB2 loaded.")
|
102 |
+
|
103 |
+
# except Exception as e:
|
104 |
+
# logging.error(e)
|
105 |
|
106 |
+
# try:
|
107 |
+
# openai_client = OpenAI(
|
108 |
+
# api_key=os.environ.get("OPENAI_API_KEY"),
|
109 |
+
# )
|
110 |
+
# # prompt = """你是一个鸟类学家,用中文回答关于鸟类的问题。你的回答需要满足以下要求:
|
111 |
+
# # 1. 你的回答必须是中文
|
112 |
+
# # 2. 回答限制在100个字以内"""
|
113 |
+
# # conv = Conversation(open_client, prompt, 3)
|
114 |
+
# logging.info(f"openai chat model loaded.")
|
115 |
+
# except Exception as e:
|
116 |
+
# logging.error(e)
|
117 |
+
|
118 |
+
# try:
|
119 |
+
# ai_model_bc_pipe= pipeline("image-classification", model="dennisjooo/Birds-Classifier-EfficientNetB2")
|
120 |
+
# logging.info(f"remote model dennisjooo/Birds-Classifier-EfficientNetB2 loaded.")
|
121 |
+
|
122 |
+
# except Exception as e:
|
123 |
+
# print(e)
|
124 |
|
125 |
#try:
|
126 |
# ai_model_ez_preprocessor = AutoTokenizer.from_pretrained("./opus-mt-en-zh")
|
|
|
136 |
#except Exception as e:
|
137 |
# print(e)
|
138 |
|
139 |
+
# def bird_classifier(image_file: str) -> str:
|
140 |
+
# # Opening the image using PIL
|
141 |
+
# img = Image.open(image_file)
|
142 |
+
# logging.info(f"image file {image_file} is opened.")
|
143 |
+
|
144 |
+
# result:str = ""
|
145 |
+
# try:
|
146 |
+
# inputs = ai_model_bc_preprocessor(img, return_tensors="pt")
|
147 |
+
|
148 |
+
# # Running the inference
|
149 |
+
# with torch.no_grad():
|
150 |
+
# logits = ai_model_bc_model(**inputs).logits
|
151 |
+
|
152 |
+
# # Getting the predicted label
|
153 |
+
# predicted_label = logits.argmax(-1).item()
|
154 |
+
# result = ai_model_bc_model.config.id2label[predicted_label]
|
155 |
+
# logging.info(f"{ai_model_bc_model.config.id2label[predicted_label]}:{ai_model_bc_pipe(img)[0]['label']}")
|
156 |
+
# except Exception as e:
|
157 |
+
# logging.error(e)
|
158 |
|
159 |
|
160 |
+
# logging.info(result)
|
161 |
+
# return result
|
162 |
|
163 |
# def text_en_zh(text_en: str) -> str:
|
164 |
# text_zh = ""
|
|
|
172 |
|
173 |
# return text_zh
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
+
# # Route to list all items uploaded by a specific user by unionid
|
177 |
+
# # @app.get("/items/{user_unionid}")
|
178 |
+
# # def list_items(user_unionid: str) -> dict[str, list[ItemInHistory]]:
|
179 |
+
# # logging.info("list_items")
|
180 |
+
# # logging.info(user_unionid)
|
|
|
|
|
|
|
181 |
|
182 |
+
# # items: list[ItemInHistory] = []
|
|
|
|
|
183 |
|
184 |
+
# # response = client.list_objects(
|
185 |
+
# # Bucket=cos_bucket,
|
186 |
+
# # Prefix=f'{user_unionid}/history/'
|
187 |
+
# # )
|
188 |
|
189 |
+
# # logging.info(response['Contents'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
+
# # for obj in response['Contents']:
|
192 |
+
# # key:str = obj['Key']
|
193 |
+
# # response = client.get_object(
|
194 |
+
# # Bucket = cos_bucket,
|
195 |
+
# # Key = key
|
196 |
+
# # )
|
197 |
+
# # localfile = key.split('/')[2]
|
198 |
+
# # response['Body'].get_stream_to_file(localfile)
|
199 |
+
|
200 |
+
# # item = itemFromJsonFile(localfile)
|
201 |
+
# # items.append(item)
|
202 |
+
|
203 |
+
# return {"items": items}
|
204 |
+
|
205 |
+
# # Route to list all items uploaded by a specific user by unionid from header
|
206 |
+
# @app.get("/items/")
|
207 |
+
# def list_items_byheader(x_wx_openid: Optional[str]=Header(None)) -> dict[str, list[ItemInHistory]]:
|
208 |
+
# logging.info("list_items_byheader")
|
209 |
+
# logging.info(x_wx_openid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
|
211 |
# items: list[ItemInHistory] = []
|
212 |
|
213 |
# response = client.list_objects(
|
214 |
# Bucket=cos_bucket,
|
215 |
+
# Prefix=f'{x_wx_openid}/history/'
|
216 |
# )
|
217 |
|
218 |
# logging.info(response['Contents'])
|
|
|
229 |
# item = itemFromJsonFile(localfile)
|
230 |
# items.append(item)
|
231 |
|
232 |
+
# return {"items": items}
|
233 |
+
|
234 |
+
|
235 |
+
# def itemFromJsonFile(jsonfile: str) -> ItemInHistory:
|
236 |
+
# f = open(jsonfile, 'r')
|
237 |
+
# content = f.read()
|
238 |
+
# a = json.loads(content)
|
239 |
+
# f.close()
|
240 |
+
# return ItemInHistory(history_id = a['history_id'],union_id = a['union_id'],
|
241 |
+
# item_fileurl = a['item_fileurl'],item_mediatype = a["item_mediatype"],
|
242 |
+
# upload_datetime = a["upload_datetime"],ai_feedback = a['ai_feedback'])
|
243 |
+
|
244 |
+
|
245 |
+
# def itemToJsonFile(item: ItemInHistory):
|
246 |
+
# history_json = {
|
247 |
+
# "history_id": item.history_id,
|
248 |
+
# "union_id": item.union_id,
|
249 |
+
# "item_fileurl": item.item_fileurl,
|
250 |
+
# "item_mediatype": item.item_mediatype,
|
251 |
+
# "upload_datetime": item.upload_datetime,
|
252 |
+
# "ai_feedback": item.ai_feedback
|
253 |
+
# }
|
254 |
+
# b = json.dumps(history_json)
|
255 |
+
# historyfile = f'{item.history_id}.json'
|
256 |
+
# f = open(historyfile, 'w')
|
257 |
+
# f.write(b)
|
258 |
+
# f.close()
|
259 |
+
|
260 |
+
# return historyfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
|
models.py
CHANGED
@@ -1,24 +1,17 @@
|
|
1 |
-
from
|
2 |
-
from typing import Optional
|
3 |
from pydantic import BaseModel, Field
|
4 |
-
import json
|
5 |
|
6 |
-
class
|
|
|
7 |
union_id: str = Field(title="the user unionid of the item uploaded",examples=["oR_-n69II04mrTuFOFyqiAt_Wgbk"])
|
8 |
item_fileurl: str = Field(title="the file url of the item uploaded",examples=["cloud://prod-3g52ms9o7a81f23c.7072-prod-3g52ms9o7a81f23c-1324125412/oR_-n69II04mrTuFOFyqiAt_Wgbk/202402022042282841.jpg"])
|
9 |
item_mediatype: str = Field(title="the media type of the item uploaded",examples=["image"])
|
10 |
-
upload_datetime: str = Field(title="the upload datetime of the item uploaded",examples=["2024-2-
|
11 |
|
12 |
-
class
|
13 |
-
|
14 |
-
union_id: str = Field(title="the user unionid of the item
|
15 |
-
item_fileurl: str = Field(title="the file url of the item
|
16 |
-
item_mediatype: str = Field(title="the media type of the item
|
17 |
-
upload_datetime: str = Field(title="the upload datetime of the item
|
18 |
-
ai_feedback: str = Field(title="the ai feedback to the item in history",examples=["AZARAS SPINETAIL"])
|
19 |
-
|
20 |
-
class ServiceLoginInfo(BaseModel):
|
21 |
-
appid: str = Field(title="appid of wx miniprogram",examples=[""])
|
22 |
-
secret: str = Field(title="secret of wx miniprogram",examples=[""])
|
23 |
-
js_code: str = Field(title="res.code return from wx.login()",examples=[""])
|
24 |
-
grant_type: str = Field(title="grant_type = authorization_code",examples=["authorization_code"])
|
|
|
1 |
+
# from typing import Optional
|
|
|
2 |
from pydantic import BaseModel, Field
|
|
|
3 |
|
4 |
+
class Item2AI(BaseModel):
|
5 |
+
upload_id: str = Field(title="the unique id of the item in uploaded",examples=["202402022042282841"])
|
6 |
union_id: str = Field(title="the user unionid of the item uploaded",examples=["oR_-n69II04mrTuFOFyqiAt_Wgbk"])
|
7 |
item_fileurl: str = Field(title="the file url of the item uploaded",examples=["cloud://prod-3g52ms9o7a81f23c.7072-prod-3g52ms9o7a81f23c-1324125412/oR_-n69II04mrTuFOFyqiAt_Wgbk/202402022042282841.jpg"])
|
8 |
item_mediatype: str = Field(title="the media type of the item uploaded",examples=["image"])
|
9 |
+
upload_datetime: str = Field(title="the upload datetime of the item uploaded",examples=["2024-2-2 20:42:28"])
|
10 |
|
11 |
+
class AI2Item(BaseModel):
|
12 |
+
upload_id: str = Field(title="the unique id of the item in uploaded",examples=["202402022042282841"])
|
13 |
+
union_id: str = Field(title="the user unionid of the item uploaded",examples=["oR_-n69II04mrTuFOFyqiAt_Wgbk"])
|
14 |
+
item_fileurl: str = Field(title="the file url of the item uploaded",examples=["cloud://prod-3g52ms9o7a81f23c.7072-prod-3g52ms9o7a81f23c-1324125412/oR_-n69II04mrTuFOFyqiAt_Wgbk/202402022042282841.jpg"])
|
15 |
+
item_mediatype: str = Field(title="the media type of the item uploaded",examples=["image"])
|
16 |
+
upload_datetime: str = Field(title="the upload datetime of the item uploaded",examples=["2024-2-2 20:42:28"])
|
17 |
+
ai_feedback: str = Field(title="the ai feedback to the item in history",examples=["AZARAS SPINETAIL"])
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,48 +1,38 @@
|
|
1 |
annotated-types==0.6.0
|
2 |
anyio==4.2.0
|
3 |
-
|
|
|
4 |
charset-normalizer==3.3.2
|
5 |
click==8.1.7
|
6 |
cos-python-sdk-v5==1.9.27
|
7 |
crcmod==1.7
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
gunicorn==21.2.0
|
13 |
h11==0.14.0
|
14 |
-
httpcore==1.0.2
|
15 |
-
httpx==0.26.0
|
16 |
-
huggingface-hub==0.20.3
|
17 |
idna==3.6
|
18 |
-
iniconfig==2.0.0
|
19 |
-
Jinja2==3.1.3
|
20 |
-
MarkupSafe==2.1.4
|
21 |
-
mpmath==1.3.0
|
22 |
-
networkx==3.2.1
|
23 |
-
numpy==1.26.3
|
24 |
-
openai==1.10.0
|
25 |
packaging==23.2
|
26 |
pillow==10.2.0
|
27 |
-
|
|
|
|
|
|
|
28 |
pycryptodome==3.20.0
|
29 |
-
pydantic==2.
|
30 |
-
pydantic_core==2.
|
31 |
-
pytest==8.0.0
|
32 |
-
python-multipart==0.0.6
|
33 |
-
PyYAML==6.0.1
|
34 |
-
regex==2023.12.25
|
35 |
requests==2.31.0
|
36 |
-
|
37 |
six==1.16.0
|
38 |
sniffio==1.3.0
|
39 |
-
starlette==0.
|
40 |
-
sympy==1.12
|
41 |
-
tokenizers==0.15.1
|
42 |
-
torch==2.1.2
|
43 |
tqdm==4.66.1
|
44 |
-
transformers==4.37.1
|
45 |
typing_extensions==4.9.0
|
46 |
-
urllib3==2.
|
47 |
-
uvicorn==0.27.0
|
48 |
xmltodict==0.13.0
|
|
|
1 |
annotated-types==0.6.0
|
2 |
anyio==4.2.0
|
3 |
+
cachetools==5.3.2
|
4 |
+
certifi==2024.2.2
|
5 |
charset-normalizer==3.3.2
|
6 |
click==8.1.7
|
7 |
cos-python-sdk-v5==1.9.27
|
8 |
crcmod==1.7
|
9 |
+
fastapi==0.109.2
|
10 |
+
google-ai-generativelanguage==0.4.0
|
11 |
+
google-api-core==2.16.2
|
12 |
+
google-auth==2.27.0
|
13 |
+
google-generativeai==0.3.2
|
14 |
+
googleapis-common-protos==1.62.0
|
15 |
+
grpcio==1.60.1
|
16 |
+
grpcio-status==1.60.1
|
17 |
gunicorn==21.2.0
|
18 |
h11==0.14.0
|
|
|
|
|
|
|
19 |
idna==3.6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
packaging==23.2
|
21 |
pillow==10.2.0
|
22 |
+
proto-plus==1.23.0
|
23 |
+
protobuf==4.25.2
|
24 |
+
pyasn1==0.5.1
|
25 |
+
pyasn1-modules==0.3.0
|
26 |
pycryptodome==3.20.0
|
27 |
+
pydantic==2.6.1
|
28 |
+
pydantic_core==2.16.2
|
|
|
|
|
|
|
|
|
29 |
requests==2.31.0
|
30 |
+
rsa==4.9
|
31 |
six==1.16.0
|
32 |
sniffio==1.3.0
|
33 |
+
starlette==0.36.3
|
|
|
|
|
|
|
34 |
tqdm==4.66.1
|
|
|
35 |
typing_extensions==4.9.0
|
36 |
+
urllib3==2.2.0
|
37 |
+
uvicorn==0.27.0.post1
|
38 |
xmltodict==0.13.0
|