Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Pre-load multiple models
|
| 5 |
+
models = {
|
| 6 |
+
"TinyBERT (NLU)": pipeline("fill-mask", model="prajjwal1/bert-tiny"),
|
| 7 |
+
"DistilBERT (NLU)": pipeline("fill-mask", model="distilbert-base-uncased"),
|
| 8 |
+
"ALBERT (NLU)": pipeline("fill-mask", model="albert-base-v2"),
|
| 9 |
+
"MobileBERT (NLU)": pipeline("fill-mask", model="google/mobilebert-uncased"),
|
| 10 |
+
"GPT-2 (text gen)": pipeline("text-generation", model="gpt2")
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
def run_model(model_name, text):
|
| 14 |
+
pipe = models[model_name]
|
| 15 |
+
if "GPT-2" in model_name:
|
| 16 |
+
return pipe(text, max_length=50, do_sample=True)[0]["generated_text"]
|
| 17 |
+
else:
|
| 18 |
+
return str(pipe(text))
|
| 19 |
+
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
gr.Markdown("# 🔥 Tiny LLM Playground\nChoose a small model and test it!")
|
| 22 |
+
|
| 23 |
+
model_choice = gr.Dropdown(list(models.keys()), label="Choose Model")
|
| 24 |
+
text_input = gr.Textbox(label="Enter text or prompt")
|
| 25 |
+
output = gr.Textbox(label="Output")
|
| 26 |
+
|
| 27 |
+
run_btn = gr.Button("Run")
|
| 28 |
+
run_btn.click(fn=run_model, inputs=[model_choice, text_input], outputs=output)
|
| 29 |
+
|
| 30 |
+
demo.launch()
|