File size: 2,359 Bytes
eac6bfb 6660e8c eac6bfb 15a2bb8 eac6bfb 15a2bb8 eac6bfb 15a2bb8 eac6bfb 15a2bb8 eac6bfb 15a2bb8 eac6bfb 15a2bb8 eac6bfb 15a2bb8 eac6bfb 15a2bb8 eac6bfb 15a2bb8 eac6bfb f228721 eac6bfb f228721 6660e8c 15a2bb8 6660e8c 15a2bb8 eac6bfb 6660e8c eac6bfb |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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()
|