# interface.py from models import BioprocessModel import io from PIL import Image import pandas as pd import numpy as np import matplotlib.pyplot as plt import torch from transformers import AutoTokenizer, AutoModelForCausalLM from sympy import symbols, sympify, lambdify import copy from config import DEVICE, MODEL_PATH, MAX_LENGTH, TEMPERATURE # Configuración del dispositivo device = DEVICE # Cargar el modelo model_path = MODEL_PATH # Reemplaza con la ruta real de tu modelo tokenizer = AutoTokenizer.from_pretrained(model_path) model = AutoModelForCausalLM.from_pretrained(model_path) model.to(device) model.eval() @torch.no_grad() def generate_analysis(prompt, max_length=MAX_LENGTH): try: input_ids = tokenizer.encode(prompt, return_tensors='pt').to(device) max_gen_length = min(max_length + input_ids.size(1), model.config.max_position_embeddings) generated_ids = model.generate( input_ids=input_ids, max_length=max_gen_length, temperature=TEMPERATURE, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True ) output_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True) analysis = output_text[len(prompt):].strip() return analysis except Exception as e: return f"Ocurrió un error durante el análisis: {e}" def parse_bounds(bounds_str, num_params): try: bounds = eval(f"[{bounds_str}]") if len(bounds) != num_params: raise ValueError lower_bounds = [b[0] for b in bounds] upper_bounds = [b[1] for b in bounds] return lower_bounds, upper_bounds except: lower_bounds = [-np.inf] * num_params upper_bounds = [np.inf] * num_params return lower_bounds, upper_bounds # Aquí incluye la función process_and_plot completa, asegurándote de que no haya referencias a decorators o @spaces.GPU def process_and_plot( # Your parameters here ): # Your implementation here # ... return [image], analysis # Importar la función create_interface desde UI.py from UI import create_interface # Si deseas ejecutar la interfaz desde este archivo, asegúrate de que este bloque no cause conflictos al importar if __name__ == "__main__": demo = create_interface() demo.launch()