File size: 717 Bytes
093a6df
19cd0d7
093a6df
9ae7984
093a6df
6e0a3a6
b37b769
093a6df
b37b769
0e4ebaf
093a6df
 
b37b769
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os
import streamlit as st
from huggingface_hub import InferenceClient
from PIL import Image
import io

def analyze_image_text(uploaded_image):
    token = os.getenv("HF_TOKEN") or st.secrets.get("HF_TOKEN")
    if not token: return "Erro: Token HF não encontrado."
    try:
        client = InferenceClient(api_key=token)
        img = Image.open(uploaded_image).convert("RGB")
        b = io.BytesIO()
        img.save(b, format='JPEG')
        res = client.document_question_answering(image=b.getvalue(), question="Describe detailed content", model="naver-clova-ix/donut-base-finetuned-docvqa")
        return res[0]['answer'] if res else "Sem texto."
    except Exception as e: return f"Erro OCR: {e}"