0x7o
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
2 |
+
import gradio as gr
|
3 |
+
import spaces
|
4 |
+
import torch
|
5 |
+
|
6 |
+
if torch.cuda.is_available():
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("ai-forever/mGPT-13B")
|
8 |
+
model = AutoModelForCausalLM.from_pretrained("ai-forever/mGPT-13B", load_in_8bit=True, device_map="auto")
|
9 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0)
|
10 |
+
|
11 |
+
@spaces.GPU
|
12 |
+
def predict(text):
|
13 |
+
return pipe(text)
|
14 |
+
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=greet,
|
17 |
+
inputs=["text"],
|
18 |
+
outputs=["text"],
|
19 |
+
)
|
20 |
+
|
21 |
+
demo.launch()
|