Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
3 |
import torch
|
4 |
-
from safetensors.torch import load_file as safetensors_load_file # Import safetensors loading function
|
5 |
from langchain.memory import ConversationBufferMemory
|
6 |
|
7 |
# Move model to device (GPU if available)
|
8 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
9 |
|
10 |
# Load the tokenizer (use pre-trained tokenizer for GPT-2 family)
|
11 |
-
tokenizer = GPT2Tokenizer.from_pretrained("
|
12 |
|
13 |
-
# Load the
|
14 |
-
|
15 |
-
|
16 |
-
# Initialize the model using the configuration
|
17 |
-
model = GPT2LMHeadModel(config)
|
18 |
-
|
19 |
-
# Load the weights from the safetensors file
|
20 |
-
model_path = "./model.safetensors" # Path to your local model file
|
21 |
-
state_dict = safetensors_load_file(model_path) # Use safetensors loader
|
22 |
-
model.load_state_dict(state_dict) # Load the state dict into the model
|
23 |
|
24 |
# Move model to the device (GPU or CPU)
|
25 |
model.to(device)
|
@@ -74,3 +65,4 @@ interface.launch()
|
|
74 |
|
75 |
|
76 |
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
3 |
import torch
|
|
|
4 |
from langchain.memory import ConversationBufferMemory
|
5 |
|
6 |
# Move model to device (GPU if available)
|
7 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
8 |
|
9 |
# Load the tokenizer (use pre-trained tokenizer for GPT-2 family)
|
10 |
+
tokenizer = GPT2Tokenizer.from_pretrained("path_to_your_model_directory")
|
11 |
|
12 |
+
# Load the model from the directory containing 'pytorch_model.bin' and 'config.json'
|
13 |
+
model = GPT2LMHeadModel.from_pretrained("path_to_your_model_directory")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Move model to the device (GPU or CPU)
|
16 |
model.to(device)
|
|
|
65 |
|
66 |
|
67 |
|
68 |
+
|