JoPmt commited on
Commit
40e06ae
·
verified ·
1 Parent(s): a262ec2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from accelerate import Accelerator
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
3
+ import gradio as gr
4
+ import os, random, gc
5
+ import torch
6
+ accelerator=Accelerator(cpu=True)
7
+ mdl = "bigcode/starcoder2-3b"
8
+ tokenizer = AutoTokenizer.from_pretrained(mdl)
9
+ model = accelerator.prepare(AutoModelForCausalLM.from_pretrained(checkpoint, torch_dtype=torch.bfloat16))
10
+ def plex(ynputs):
11
+ onputs = tokenizer.encode(""+ynputs+"", return_tensors="pt").to("cpu")
12
+ iutputs = model.generate(onputs, max_new_tokens=350)
13
+ return tokenizer.decode(iutputs[0])
14
+ with gr.Blocks() as iface:
15
+ zutput=gr.Textbox(lines=5)
16
+ znput=gr.Textbox(lines=2)
17
+ btn=gr.Button("ASK")
18
+ btn.click(fn=plex, inputs=znput, outputs=zutput)
19
+ iface.queue(max_size=1,api_open=False)
20
+ iface.launch(max_threads=20,inline=False,show_api=False)