Download app.py from 0x7o/mGPT-13B: direct link, hf CLI and curl.
- Browser
- Download file 865 Bytes
-
https://huggingface.co/spaces/0x7o/mGPT-13B/resolve/main/app.py
- Command line
-
hf download hf://spaces/0x7o/mGPT-13B/app.py
-
curl -L -o app.py https://huggingface.co/spaces/0x7o/mGPT-13B/resolve/main/app.py
865 Bytes
| import spaces | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| import gradio as gr | |
| import torch | |
| if torch.cuda.is_available(): | |
| tokenizer = AutoTokenizer.from_pretrained("ai-forever/mGPT-13B") | |
| model = AutoModelForCausalLM.from_pretrained("ai-forever/mGPT-13B", load_in_8bit=True, device_map="auto") | |
| pipe = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| def predict(prompt, temperature, max_length): | |
| return pipe(prompt, temperature=temperature, max_length=max_length, top_p=0.95, top_k=50, do_sample=True)[0]["generated_text"] | |
| demo = gr.Interface( | |
| fn=predict, | |
| title="mGPT-13B Demo", | |
| inputs=["text", gr.Slider(minimum=0.01, maximum=1.0, value=0.7, label="temperature"), gr.Slider(minimum=1, maximum=1024, value=50, label="max_length")], | |
| outputs=["text"], | |
| ) | |
| demo.launch() |