Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,20 @@
|
|
| 1 |
-
import spaces
|
| 2 |
import torch
|
| 3 |
-
from peft import PeftModel, PeftConfig
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
| 5 |
from threading import Thread
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
MODEL_PATH = "Ozaii/zephyr-bae"
|
| 9 |
|
| 10 |
-
|
| 11 |
-
def load_model():
|
| 12 |
-
print("Attempting to load Zephyr... Cross your fingers! 🤞")
|
| 13 |
-
try:
|
| 14 |
-
peft_config = PeftConfig.from_pretrained(MODEL_PATH)
|
| 15 |
-
base_model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
-
peft_config.base_model_name_or_path,
|
| 17 |
-
torch_dtype=torch.float16,
|
| 18 |
-
device_map="auto",
|
| 19 |
-
load_in_8bit=True
|
| 20 |
-
)
|
| 21 |
-
model = PeftModel.from_pretrained(base_model, MODEL_PATH, torch_dtype=torch.float16)
|
| 22 |
-
tokenizer = AutoTokenizer.from_pretrained(peft_config.base_model_name_or_path)
|
| 23 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 24 |
-
tokenizer.padding_side = "right"
|
| 25 |
-
print("Zephyr loaded successfully! Time to charm!")
|
| 26 |
-
return model, tokenizer
|
| 27 |
-
except Exception as e:
|
| 28 |
-
print(f"Oops! Zephyr seems to be playing hide and seek. Error: {str(e)}")
|
| 29 |
-
raise
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
def generate_response(prompt, max_new_tokens=128):
|
| 34 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048).to(model.device)
|
|
@@ -87,4 +73,5 @@ with gr.Blocks(css=css) as iface:
|
|
| 87 |
Remember, Zephyr is an AI and this is for fun and entertainment. Enjoy your chat! 💖
|
| 88 |
""")
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
| 3 |
from threading import Thread
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
MODEL_PATH = "Ozaii/zephyr-bae"
|
| 7 |
|
| 8 |
+
print("Attempting to load Zephyr... Cross your fingers! 🤞")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
try:
|
| 11 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, torch_dtype=torch.float16, device_map="auto")
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 13 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 14 |
+
print("Zephyr loaded successfully! Time to charm!")
|
| 15 |
+
except Exception as e:
|
| 16 |
+
print(f"Oops! Zephyr seems to be playing hide and seek. Error: {str(e)}")
|
| 17 |
+
raise
|
| 18 |
|
| 19 |
def generate_response(prompt, max_new_tokens=128):
|
| 20 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048).to(model.device)
|
|
|
|
| 73 |
Remember, Zephyr is an AI and this is for fun and entertainment. Enjoy your chat! 💖
|
| 74 |
""")
|
| 75 |
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
iface.launch()
|