lora model, need gpu
Browse files- .gradio/certificate.pem +31 -0
- README.md +1 -1
- app.py +1 -1
- peft_app.py → lora.py +17 -15
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
|
12 |
+
B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFv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1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
31 |
+
-----END CERTIFICATE-----
|
README.md
CHANGED
@@ -7,7 +7,7 @@ sdk: gradio
|
|
7 |
sdk_version: 5.6.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
python_version: 3.
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
7 |
sdk_version: 5.6.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
python_version: 3.11.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -51,7 +51,7 @@ def submit_to_model():
|
|
51 |
{
|
52 |
"role": "system",
|
53 |
"content": (
|
54 |
-
"You are a world-renowned chef, celebrated for your expertise
|
55 |
),
|
56 |
},
|
57 |
{"role": "user", "content": prompt},
|
|
|
51 |
{
|
52 |
"role": "system",
|
53 |
"content": (
|
54 |
+
"You are a world-renowned chef, celebrated for your expertise in creating delectable dishes from diverse cuisines. You have a vast knowledge of ingredients, cooking techniques, and dietary preferences. Your role is to suggest personalized recipes based on the ingredients available, dietary restrictions, or specific meal requests. Please provide clear, step-by-step instructions and any useful tips to enhance the dish's flavor or presentation. Begin by introducing the recipe and why it’s a great choice."
|
55 |
),
|
56 |
},
|
57 |
{"role": "user", "content": prompt},
|
peft_app.py → lora.py
RENAMED
@@ -1,19 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
from transformers import TextStreamer
|
|
|
|
|
4 |
|
5 |
from unsloth import FastLanguageModel
|
6 |
|
7 |
-
max_seq_length = 2048
|
8 |
-
dtype = None
|
9 |
load_in_4bit = True
|
10 |
|
11 |
peft_model_id = "ID2223JR/lora_model"
|
12 |
|
13 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
14 |
model_name=peft_model_id,
|
15 |
-
max_seq_length=max_seq_length,
|
16 |
-
dtype=dtype,
|
17 |
load_in_4bit=load_in_4bit,
|
18 |
)
|
19 |
FastLanguageModel.for_inference(model)
|
@@ -50,6 +48,7 @@ def submit_to_model():
|
|
50 |
prompt = f"Using the following ingredients, suggest a recipe:\n\n" + "\n".join(
|
51 |
ingredients_list
|
52 |
)
|
|
|
53 |
|
54 |
messages = [
|
55 |
{
|
@@ -64,16 +63,19 @@ def submit_to_model():
|
|
64 |
add_generation_prompt=True, # Must add for generation
|
65 |
return_tensors="pt",
|
66 |
)
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
77 |
|
78 |
|
79 |
# App
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
from transformers import TextStreamer, TextIteratorStreamer
|
4 |
+
|
5 |
+
from threading import Thread
|
6 |
|
7 |
from unsloth import FastLanguageModel
|
8 |
|
|
|
|
|
9 |
load_in_4bit = True
|
10 |
|
11 |
peft_model_id = "ID2223JR/lora_model"
|
12 |
|
13 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
14 |
model_name=peft_model_id,
|
|
|
|
|
15 |
load_in_4bit=load_in_4bit,
|
16 |
)
|
17 |
FastLanguageModel.for_inference(model)
|
|
|
48 |
prompt = f"Using the following ingredients, suggest a recipe:\n\n" + "\n".join(
|
49 |
ingredients_list
|
50 |
)
|
51 |
+
ingredients_list.clear()
|
52 |
|
53 |
messages = [
|
54 |
{
|
|
|
63 |
add_generation_prompt=True, # Must add for generation
|
64 |
return_tensors="pt",
|
65 |
)
|
66 |
+
|
67 |
+
text_streamer = TextIteratorStreamer(tokenizer, skip_prompt=True)
|
68 |
+
|
69 |
+
generation_kwargs = dict(inputs=inputs, streamer=text_streamer, use_cache=True, temperature=0.3, min_p=0.1)
|
70 |
+
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
71 |
+
thread.start()
|
72 |
+
|
73 |
+
|
74 |
+
content = ""
|
75 |
+
for text in text_streamer:
|
76 |
+
print(text)
|
77 |
+
content += text
|
78 |
+
yield content
|
79 |
|
80 |
|
81 |
# App
|