Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,8 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from peft import AutoPeftModelForCausalLM
|
3 |
from transformers import AutoTokenizer
|
4 |
|
5 |
-
# Load the model and tokenizer
|
6 |
-
load_in_4bit = True # Adjust based on your setup
|
7 |
-
model = AutoPeftModelForCausalLM.from_pretrained(
|
8 |
-
"shakaryan/lebedev_qwen2.5",
|
9 |
-
load_in_4bit=load_in_4bit,
|
10 |
-
)
|
11 |
-
tokenizer = AutoTokenizer.from_pretrained("shakaryan/lebedev_qwen2.5")
|
12 |
-
|
13 |
# Define the prompt template
|
14 |
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
15 |
|
@@ -22,10 +15,17 @@ alpaca_prompt = """Below is an instruction that describes a task, paired with an
|
|
22 |
### Response:
|
23 |
{}"""
|
24 |
|
25 |
-
EOS_TOKEN = tokenizer.eos_token # Ensure proper sequence termination
|
26 |
-
|
27 |
# Function to generate responses
|
|
|
28 |
def generate_response(input_text, instruction_text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# Format the prompt
|
30 |
formatted_prompt = alpaca_prompt.format(instruction_text, input_text, "") + EOS_TOKEN
|
31 |
# Tokenize and generate response
|
@@ -46,7 +46,7 @@ with gr.Blocks() as demo:
|
|
46 |
with gr.Row():
|
47 |
instruction_text = gr.Textbox(
|
48 |
label="Instruction Text",
|
49 |
-
value="You are a blogger named Artemiy Lebedev, your purpose is to generate a post
|
50 |
lines=3,
|
51 |
)
|
52 |
with gr.Row():
|
|
|
1 |
import gradio as gr
|
2 |
+
import spaces
|
3 |
from peft import AutoPeftModelForCausalLM
|
4 |
from transformers import AutoTokenizer
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Define the prompt template
|
7 |
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
8 |
|
|
|
15 |
### Response:
|
16 |
{}"""
|
17 |
|
|
|
|
|
18 |
# Function to generate responses
|
19 |
+
@spaces.GPU
|
20 |
def generate_response(input_text, instruction_text):
|
21 |
+
# Load the model and tokenizer within the GPU context
|
22 |
+
model = AutoPeftModelForCausalLM.from_pretrained(
|
23 |
+
"shakaryan/lebedev_qwen2.5",
|
24 |
+
load_in_4bit=True, # Adjust based on your setup
|
25 |
+
).to("cuda")
|
26 |
+
tokenizer = AutoTokenizer.from_pretrained("shakaryan/lebedev_qwen2.5")
|
27 |
+
EOS_TOKEN = tokenizer.eos_token # Ensure proper sequence termination
|
28 |
+
|
29 |
# Format the prompt
|
30 |
formatted_prompt = alpaca_prompt.format(instruction_text, input_text, "") + EOS_TOKEN
|
31 |
# Tokenize and generate response
|
|
|
46 |
with gr.Row():
|
47 |
instruction_text = gr.Textbox(
|
48 |
label="Instruction Text",
|
49 |
+
value="You are a blogger named Artemiy Lebedev, your purpose is to generate a post in Russian based on the post article",
|
50 |
lines=3,
|
51 |
)
|
52 |
with gr.Row():
|