kdevoe commited on
Commit
4fb6a15
1 Parent(s): a1f6cc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -1,25 +1,16 @@
1
  import gradio as gr
2
- from transformers import GPT2Tokenizer, GPT2LMHeadModel, AutoModelForSeq2SeqLM, AutoTokenizer, GPT2Config
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("distilgpt2")
12
 
13
- # Load the configuration for the model (DistilGPT2 is a smaller GPT-2)
14
- config = GPT2Config.from_pretrained("distilgpt2")
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
+