samwell commited on
Commit
29e2510
1 Parent(s): f7186cd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import gradio as gr
4
+ from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
5
+
6
+ def generate_sequences(model_name, prompt):
7
+ if model_name == "nferruz/ProtGPT2":
8
+ protgpt2 = pipeline('text-generation', model="nferruz/ProtGPT2")
9
+ sequences = protgpt2(prompt, max_length=100, do_sample=True, top_k=950, repetition_penalty=1.2, num_return_sequences=10, eos_token_id=0)
10
+ return "\n".join([seq['generated_text'] for seq in sequences])
11
+ elif model_name == "lightonai/RITA_xl":
12
+ model = AutoModelForCausalLM.from_pretrained("lightonai/RITA_xl", trust_remote_code=True)
13
+ tokenizer = AutoTokenizer.from_pretrained("lightonai/RITA_xl")
14
+ rita_gen = pipeline('text-generation', model=model, tokenizer=tokenizer)
15
+ 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)
16
+ return "\n".join([seq['generated_text'].replace(' ', '') for seq in sequences])
17
+ else:
18
+ return "Model not supported"
19
+
20
+ model_options = ["nferruz/ProtGPT2", "lightonai/RITA_xl"]
21
+
22
+ gr.Interface(
23
+ fn=generate_sequences,
24
+ inputs=[
25
+ gr.Dropdown(model_options, label="Select Model"),
26
+ gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt")
27
+ ],
28
+ outputs="text",
29
+ title="Sequence Generation with Transformers",
30
+ description="Generate sequences using selected transformer models."
31
+ ).launch()