getomni-ai / zerox

PDF to Markdown with vision models
https://getomni.ai/ocr-demo
MIT License
6.58k stars 358 forks source link

No text in user content for Gemini model and None form Openai modle #69

Closed yixian3500 closed 1 month ago

yixian3500 commented 1 month ago

Hi,

thanks to the good project, but anyone can help me about this problem?

My python code is :

from pyzerox import zerox import os import json import asyncio import nest_asyncio

nest_asyncio.apply()

Model Setup (Use only Vision Models) Refer: https://docs.litellm.ai/docs/providers

placeholder for additional model kwargs which might be required for some models

kwargs = {}

system prompt to use for the vision model

custom_system_prompt = None

to override

custom_system_prompt = "For the below pdf page, please output all the words" ## example

###################### Example for OpenAI ######################

model = "gpt-4o-mini" ## openai model

os.environ["OPENAI_API_KEY"] = "keykeykye" ## your-api-key

###################### Example for Gemini ######################

model = "gemini/gemini-1.5-flash" ## "gemini/" -> format / os.environ['GEMINI_API_KEY'] = "keykeykey" # your-gemini-api-key

###################### For other providers refer: https://docs.litellm.ai/docs/providers ######################

Define main async entrypoint

import asyncio

Define main async entrypoint

async def main(): file_path = "/Users/longgongmeishi/Downloads/aaa.pdf" ## local filepath and file URL supported

## process only some pages or all
select_pages = [1,2,3,4] ## None for all, but could be int or list(int) page numbers (1 indexed)

output_dir = "./output_test" ## directory to save the consolidated markdown file
result = await zerox(file_path=file_path, model=model, output_dir=output_dir,
                    custom_system_prompt=custom_system_prompt,select_pages=select_pages, **kwargs)
return result

获取当前事件循环

loop = asyncio.get_event_loop()

运行主函数,直到完成

markdown_result = loop.run_until_complete(main())

打印结果

print("Markdown result:") print(result)

it return this:

20:01:40 - LiteLLM:WARNING: vertex_ai_non_gemini.py:198 - No text in user content. Adding a blank text to user content, to ensure Gemini doesn't fail the request. Relevant Issue - https://github.com/BerriAI/litellm/issues/5515 20:01:40 - LiteLLM:WARNING: vertex_ai_non_gemini.py:198 - No text in user content. Adding a blank text to user content, to ensure Gemini doesn't fail the request. Relevant Issue - https://github.com/BerriAI/litellm/issues/5515 Markdown result:

NameError Traceback (most recent call last) Cell In[7], line 53 51 # 打印结果 52 print("Markdown result:") ---> 53 print(result)

NameError: name 'result' is not defined

if I change to open_ai model, it returned :

Markdown result:

NameError Traceback (most recent call last) Cell In[9], line 53 51 # 打印结果 52 print("Markdown result:") ---> 53 print(result)

NameError: name 'result' is not defined

yixian3500 commented 1 month ago

I got it!

The reason is the variable result is not recognized in the scope where I'm trying to print it. This is because the result variable is defined inside the main function, and its scope is limited to that function.

I replaced the print(result) with print(markdown_result) and it works!

yixian3500 commented 1 month ago

close this cuz it works