Spaces:
Sleeping
Sleeping
Benjamin Gonzalez
commited on
Commit
·
5315eed
1
Parent(s):
f647657
switch to gradio
Browse files
app.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
-
import
|
3 |
|
4 |
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
|
5 |
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", flash_attn=True, flash_rotary=True, fused_dense=True, device_map="cuda", trust_remote_code=True)
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import gradio as gr
|
3 |
|
4 |
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
|
5 |
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", flash_attn=True, flash_rotary=True, fused_dense=True, device_map="cuda", trust_remote_code=True)
|
6 |
|
7 |
+
def generate(prompt, length):
|
8 |
+
inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=False)
|
9 |
+
outputs = model.generate(**inputs, max_length=length)
|
10 |
+
return tokenizer.batch_decode(outputs)[0]
|
11 |
+
|
12 |
+
demo = gr.Interface(fn=generate, inputs=["text", "number"], outputs="text")
|
13 |
+
|
14 |
+
if __name__ == "__main__":
|
15 |
+
demo.launch(show_api=False)
|