Spaces:
Sleeping
Sleeping
File size: 1,330 Bytes
dbb647b |
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 36 37 38 39 40 41 42 43 44 45 46 |
import gradio as gr
from transformers import AutoModel
import torch
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
# Carregar modelo Surya
model_name = "nasa-ibm-ai4science/Surya-1.0"
model = AutoModel.from_pretrained(model_name)
model.eval()
# Função para gerar heatmap
def infer_solar_image_heatmap(img):
# Pré-processamento: grayscale, resize 224x224
img = img.convert("L").resize((224, 224))
img_tensor = torch.tensor(np.array(img), dtype=torch.float32).unsqueeze(0).unsqueeze(0) / 255.0
with torch.no_grad():
outputs = model(img_tensor)
# Pegar os primeiros canais e reshapar para visualização
emb = outputs[0].squeeze().numpy()
heatmap = emb - emb.min()
heatmap /= heatmap.max() + 1e-8 # normalização 0-1
# Criar figura
plt.imshow(heatmap, cmap='hot')
plt.axis('off')
plt.tight_layout()
# Salvar figura em buffer
fig = plt.gcf()
return fig
# Interface Gradio
interface = gr.Interface(
fn=infer_solar_image_heatmap,
inputs=gr.Image(type="pil"),
outputs=gr.Plot(label="Heatmap do embedding Surya"),
title="Playground Surya-1.0 com Heatmap",
description="Upload de imagem solar → visualize heatmap gerado pelo Surya-1.0"
)
interface.launch()
|