Spaces:
Sleeping
Sleeping
app.py
Browse filesmeu primeiro modelo
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModel, AutoTokenizer
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# Carregar o modelo e tokenizador
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
|
8 |
+
model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True,
|
9 |
+
device_map='cuda', use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
|
10 |
+
model = model.eval().cuda()
|
11 |
+
|
12 |
+
# Título do app no Streamlit
|
13 |
+
st.title('OCR com Modelo Pré-treinado')
|
14 |
+
|
15 |
+
# Carregando a imagem
|
16 |
+
uploaded_file = st.file_uploader("Faça o upload de uma imagem", type=["jpg", "jpeg", "png"])
|
17 |
+
|
18 |
+
if uploaded_file is not None:
|
19 |
+
# Exibir a imagem
|
20 |
+
image = Image.open(uploaded_file)
|
21 |
+
st.image(image, caption='Imagem carregada', use_column_width=True)
|
22 |
+
|
23 |
+
# Salvar a imagem para processamento (opcional)
|
24 |
+
image.save("uploaded_image.jpg")
|
25 |
+
|
26 |
+
# Executando OCR na imagem carregada
|
27 |
+
with st.spinner('Processando a imagem...'):
|
28 |
+
# Realizando o OCR
|
29 |
+
res = model.chat(tokenizer, "uploaded_image.jpg", ocr_type='ocr')
|
30 |
+
|
31 |
+
# Exibindo o resultado do OCR
|
32 |
+
st.subheader("Texto Extraído:")
|
33 |
+
st.text(res)
|
34 |
+
else:
|
35 |
+
st.info("Por favor, faça o upload de uma imagem para continuar.")
|