rinrikatoki commited on
Commit
e66ee38
·
verified ·
1 Parent(s): 33ed540

changed a section in app.py and added the requirements.txt

Browse files
Files changed (2) hide show
  1. app.py +38 -31
  2. requirements.txt +6 -0
app.py CHANGED
@@ -1,31 +1,38 @@
1
- import torch
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
- from peft import PeftModel
4
- import gradio as gr
5
-
6
- BASE_MODEL = "PartAI/Dorna-Llama3-8B-Instruct"
7
- LORA_PATH = "./dorna-diabetes-finetuned" # این پوشه رو آپلود می‌کنی توی اسپیس
8
-
9
- tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
10
-
11
- base_model = AutoModelForCausalLM.from_pretrained(
12
- BASE_MODEL,
13
- device_map="auto",
14
- torch_dtype=torch.float16,
15
- )
16
-
17
- model = PeftModel.from_pretrained(base_model, LORA_PATH)
18
-
19
- def generate_response(prompt):
20
- input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
21
- with torch.no_grad():
22
- output = model.generate(
23
- input_ids=input_ids,
24
- max_new_tokens=200,
25
- do_sample=True,
26
- temperature=0.7,
27
- top_p=0.9,
28
- )
29
- return tokenizer.decode(output[0], skip_special_tokens=True)
30
-
31
- gr.Interface(fn=generate_response, inputs="text", outputs="text", title="Dorna-Llama3 LoRA").launch()
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ from peft import PeftModel
4
+ import gradio as gr
5
+ import os
6
+ import zipfile
7
+
8
+ if not os.path.exists("dorna-diabetes-finetuned"):
9
+ with zipfile.ZipFile("dorna-diabetes-finetuned.zip", "r") as zip_ref:
10
+ zip_ref.extractall(".")
11
+ print("✅ فایل ZIP اکسترکت شد.")
12
+
13
+ BASE_MODEL = "PartAI/Dorna-Llama3-8B-Instruct"
14
+ LORA_PATH = "./dorna-diabetes-finetuned" # این پوشه رو آپلود می‌کنی توی اسپیس
15
+
16
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
17
+
18
+ base_model = AutoModelForCausalLM.from_pretrained(
19
+ BASE_MODEL,
20
+ device_map="auto",
21
+ torch_dtype=torch.float16,
22
+ )
23
+
24
+ model = PeftModel.from_pretrained(base_model, LORA_PATH)
25
+
26
+ def generate_response(prompt):
27
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
28
+ with torch.no_grad():
29
+ output = model.generate(
30
+ input_ids=input_ids,
31
+ max_new_tokens=200,
32
+ do_sample=True,
33
+ temperature=0.7,
34
+ top_p=0.9,
35
+ )
36
+ return tokenizer.decode(output[0], skip_special_tokens=True)
37
+
38
+ gr.Interface(fn=generate_response, inputs="text", outputs="text", title="Dorna-Llama3 LoRA").launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers
2
+ peft
3
+ accelerate
4
+ torch
5
+ bitsandbytes
6
+ gradio