|
|
|
|
|
import gradio as gr |
|
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 |
|
|
|
|
|
device = DEVICE |
|
|
|
|
|
model_path = MODEL_PATH |
|
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 |
|
|
|
|
|
|
|
def process_and_plot( |
|
file, |
|
|
|
|
|
): |
|
|
|
|
|
pass |
|
|
|
|
|
from UI import create_interface |
|
|
|
|
|
if __name__ == "__main__": |
|
demo = create_interface() |
|
demo.launch() |
|
|