|
|
|
import transformers |
|
from transformers import GraphormerForGraphClassification |
|
import gradio as gr |
|
|
|
import os |
|
try: |
|
import toml |
|
except ImportError: |
|
os.system('pip install toml') |
|
import toml |
|
print('todo en orden') |
|
model = GraphormerForGraphClassification.from_pretrained("PedroLancharesSanchez/graph-regression") |
|
|
|
def predict(instancia): |
|
instancia_preprocesada=preprocess_item(instancia) |
|
inputs={} |
|
inputs['input_nodes'] = torch.tensor([instancia_preprocesada['input_nodes']]) |
|
inputs['input_edges'] = torch.tensor([instancia_preprocesada['input_edges']]) |
|
inputs['attn_bias'] = torch.tensor([instancia_preprocesada['attn_bias']]) |
|
inputs['in_degree'] = torch.tensor([instancia_preprocesada['in_degree']]) |
|
inputs['out_degree'] = torch.tensor([instancia_preprocesada['out_degree']]) |
|
inputs['spatial_pos'] = torch.tensor([instancia_preprocesada['spatial_pos']]) |
|
inputs['attn_edge_type'] = torch.tensor([instancia_preprocesada['attn_edge_type']]) |
|
with torch.no_grad(): |
|
logits = model(**inputs).logits |
|
predicted_class_id = logits.argmax().item() |
|
return logits |
|
|
|
graph_input = gr.inputs.Graph(graph_type="networkx", label="Grafo de entrada") |
|
regression_output = gr.outputs.Textbox(label="Valor de regresión") |
|
|
|
gr.Interface(fn=predict, inputs=graph_input, outputs=regression_output,examples=['grafo1.json','grafo2.json']).launch(share=False) |
|
|