|
|
|
|
|
import gradio as gr |
|
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer |
|
|
|
def generate_sequences(model_name, prompt): |
|
if model_name == "nferruz/ProtGPT2": |
|
protgpt2 = pipeline('text-generation', model="nferruz/ProtGPT2") |
|
sequences = protgpt2(prompt, max_length=100, do_sample=True, top_k=950, repetition_penalty=1.2, num_return_sequences=10, eos_token_id=0) |
|
return "\n".join([seq['generated_text'] for seq in sequences]) |
|
elif model_name == "lightonai/RITA_xl": |
|
model = AutoModelForCausalLM.from_pretrained("lightonai/RITA_xl", trust_remote_code=True) |
|
tokenizer = AutoTokenizer.from_pretrained("lightonai/RITA_xl") |
|
rita_gen = pipeline('text-generation', model=model, tokenizer=tokenizer) |
|
sequences = rita_gen(prompt, max_length=20, do_sample=True, top_k=950, repetition_penalty=1.2, num_return_sequences=2, eos_token_id=2) |
|
return "\n".join([seq['generated_text'].replace(' ', '') for seq in sequences]) |
|
else: |
|
return "Model not supported" |
|
|
|
model_options = ["nferruz/ProtGPT2", "lightonai/RITA_xl"] |
|
|
|
gr.Interface( |
|
fn=generate_sequences, |
|
inputs=[ |
|
gr.Dropdown(model_options, label="Select Model"), |
|
gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt") |
|
], |
|
outputs="text", |
|
title="Novel Protein Sequence Generation", |
|
description="Generate sequences using selected protein language models." |
|
).launch() |
|
|