Update app.py
Browse files
app.py
CHANGED
|
@@ -2,17 +2,11 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
|
| 5 |
-
model_name = "
|
| 6 |
-
|
| 7 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 8 |
-
model_name,
|
| 9 |
-
trust_remote_code=True,
|
| 10 |
-
use_fast=False
|
| 11 |
-
)
|
| 12 |
|
|
|
|
| 13 |
model = AutoModelForCausalLM.from_pretrained(
|
| 14 |
model_name,
|
| 15 |
-
trust_remote_code=True,
|
| 16 |
torch_dtype=torch.float32,
|
| 17 |
low_cpu_mem_usage=True
|
| 18 |
)
|
|
@@ -20,32 +14,36 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 20 |
model.eval()
|
| 21 |
|
| 22 |
def generate(prompt):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
)
|
| 31 |
|
|
|
|
|
|
|
| 32 |
with torch.no_grad():
|
| 33 |
-
|
| 34 |
**inputs,
|
| 35 |
max_new_tokens=256,
|
| 36 |
-
do_sample=True,
|
| 37 |
temperature=0.7,
|
| 38 |
-
|
| 39 |
)
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
gr.Interface(
|
| 46 |
fn=generate,
|
| 47 |
-
inputs=gr.Textbox(lines=4
|
| 48 |
-
outputs=
|
| 49 |
-
title="
|
| 50 |
-
description="Powered by Gemma-4-E2B"
|
| 51 |
).launch()
|
|
|
|
| 2 |
import torch
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
|
| 5 |
+
model_name = "ICEPVP8977/Uncensored_Qwen2.5_Coder_3B"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
model_name,
|
|
|
|
| 10 |
torch_dtype=torch.float32,
|
| 11 |
low_cpu_mem_usage=True
|
| 12 |
)
|
|
|
|
| 14 |
model.eval()
|
| 15 |
|
| 16 |
def generate(prompt):
|
| 17 |
+
messages = [
|
| 18 |
+
{"role": "user", "content": prompt}
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
text = tokenizer.apply_chat_template(
|
| 22 |
+
messages,
|
| 23 |
+
tokenize=False,
|
| 24 |
+
add_generation_prompt=True
|
| 25 |
)
|
| 26 |
|
| 27 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 28 |
+
|
| 29 |
with torch.no_grad():
|
| 30 |
+
outputs = model.generate(
|
| 31 |
**inputs,
|
| 32 |
max_new_tokens=256,
|
|
|
|
| 33 |
temperature=0.7,
|
| 34 |
+
do_sample=True
|
| 35 |
)
|
| 36 |
|
| 37 |
+
response = tokenizer.decode(
|
| 38 |
+
outputs[0][inputs["input_ids"].shape[-1]:],
|
| 39 |
+
skip_special_tokens=True
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
return response
|
| 43 |
|
| 44 |
gr.Interface(
|
| 45 |
fn=generate,
|
| 46 |
+
inputs=gr.Textbox(lines=4),
|
| 47 |
+
outputs="text",
|
| 48 |
+
title="Qwen2.5 Coder 3B"
|
|
|
|
| 49 |
).launch()
|