Spaces:
Running
Running
| 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}" | |