File size: 1,272 Bytes
dbdbddf ac800d9 dbdbddf ac800d9 2d19186 8b21536 2d19186 dbdbddf ac800d9 03ec03d ac800d9 2d19186 89fdbfc ac800d9 fe10d73 1cfd79c fe10d73 0e4fd71 dbdbddf fe10d73 0e4fd71 fe10d73 a6094b4 fe10d73 dbdbddf fe10d73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
from PIL import Image
import google.generativeai as genai
api_key = 'AIzaSyB7-RzBwTAfVA-7ZGk2mEOQwOxshpwzhpM' # put your API key here
genai.configure(api_key=api_key)
geminiModel = genai.GenerativeModel(model_name='gemini-pro-vision')
title="DocTR OCR (PDL Demo)"
description="Upload an image to get the OCR results !"
def greet(img):
# generate text
prompt = "the input text in vietnamese, please add accend and take this peace of information and give all the information in point wise better format also give some recomendation related to them"
# print(prompt)
response = geminiModel.generate_content([prompt,img], stream=True)
response.resolve()
print(response)
res = response.text
_output_name = "RESULT_OCR.txt"
_output_name_pdf="RESULT_OCR.pdf"
open(_output_name, 'w').close() # clear file
with open(_output_name, "w", encoding="utf-8", errors="ignore") as f:
f.write(res)
print("Writing into file")
return res, _output_name
demo = gr.Interface(fn=greet,
inputs=gr.Image(type="pil"),
outputs=["text", "file"],
title=title,
description=description
)
demo.launch(debug=True) |