Spaces:
Sleeping
Sleeping
injilashah
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
b_tokenizer = AutoTokenizer.from_pretrained("bigscience/bloom-560m")#using small parameter version of model for faster inference on hf
|
5 |
+
b_model = AutoModelForCausalLM.from_pretrained("bigscience/bloom-560m")
|
6 |
+
|
7 |
+
g_tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")#using small paramerter version of model for faster inference on hf
|
8 |
+
g_model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b")
|
9 |
+
|
10 |
+
def Sentence_Commpletion(model_name, input_text):
|
11 |
+
|
12 |
+
if model_name == "Bloom":
|
13 |
+
tokenizer, model = b_tokenizer, b_model
|
14 |
+
elif model_name == "Gemma":
|
15 |
+
tokenizer, model = g_tokenizer, g_model
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
20 |
+
outputs = model.generate(inputs.input_ids, max_length=50, num_return_sequences=1)
|
21 |
+
|
22 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
+
|
24 |
+
|
25 |
+
interface = gr.Interface(
|
26 |
+
fn=Sentence_Commpletion,
|
27 |
+
inputs=[gr.Radio(["Bloom", "Gemma"], label="Choose model"),
|
28 |
+
|
29 |
+
gr.Textbox(placeholder="Enter sentece"),],
|
30 |
+
outputs="text",
|
31 |
+
title="Bloom vs Gemma Sentence completion",
|
32 |
+
|
33 |
+
)
|
34 |
+
|
35 |
+
|
36 |
+
interface.launch()
|