Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -352,25 +352,6 @@ def generate_gpt2_xl(prompt):
|
|
352 |
return response
|
353 |
|
354 |
|
355 |
-
def answer_question_minicpm(image_bytes, question):
|
356 |
-
blob_name = f"transformers/minicpm_answer:{hash(image_bytes)}:{question}"
|
357 |
-
answer = load_object_from_gcs(blob_name)
|
358 |
-
if not answer:
|
359 |
-
try:
|
360 |
-
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
361 |
-
with tqdm(total=1, desc="Answering question with MiniCPM") as pbar:
|
362 |
-
msgs = [{"role": "user", "content": [image, question]}]
|
363 |
-
answer = minicpm_model.chat(
|
364 |
-
image=None, msgs=msgs, tokenizer=minicpm_tokenizer
|
365 |
-
)
|
366 |
-
pbar.update(1)
|
367 |
-
save_object_to_gcs(blob_name, answer)
|
368 |
-
except Exception as e:
|
369 |
-
print(f"Failed to answer question with MiniCPM: {e}")
|
370 |
-
return None
|
371 |
-
return answer
|
372 |
-
|
373 |
-
|
374 |
def store_user_question(question):
|
375 |
blob_name = "user_questions.txt"
|
376 |
blob = bucket.blob(blob_name)
|
|
|
352 |
return response
|
353 |
|
354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
def store_user_question(question):
|
356 |
blob_name = "user_questions.txt"
|
357 |
blob = bucket.blob(blob_name)
|