Spaces:
Runtime error
Runtime error
A B Vijay Kumar
commited on
Commit
·
9666f6c
1
Parent(s):
51a06b6
Update app.py
Browse filesUpdated the logic
app.py
CHANGED
|
@@ -1,7 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
model_name = "Salesforce/codegen-350M-mono"
|
| 6 |
+
base_model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=bnb_config, use_cache = False, device_map=device_map)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 8 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 9 |
+
tokenizer.padding_side = "right"
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def query(instruction, input):
|
| 15 |
+
prompt = f"""### Instruction:
|
| 16 |
+
Use the Task below and the Input given to write the Response, which is a programming code that can solve the Task.
|
| 17 |
+
### Task:
|
| 18 |
+
{instruction}
|
| 19 |
+
### Input:
|
| 20 |
+
{input}
|
| 21 |
+
### Response:
|
| 22 |
+
"""
|
| 23 |
+
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
|
| 24 |
+
output_base = base_model.generate(input_ids=input_ids, max_new_tokens=500, do_sample=True, top_p=0.9,temperature=0.5)
|
| 25 |
+
response = "{tokenizer.batch_decode(output_base.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}"
|
| 26 |
+
return response
|
| 27 |
+
|
| 28 |
+
inputs = ["text", "text"]
|
| 29 |
+
outputs = "text"
|
| 30 |
+
iface = gr.Interface(fn=query, inputs="text", outputs="text")
|
| 31 |
iface.launch()
|