Spaces:
Sleeping
Sleeping
Update push_model.py
Browse files- push_model.py +56 -12
push_model.py
CHANGED
@@ -1,17 +1,61 @@
|
|
|
|
1 |
from transformers import AutoTokenizer
|
2 |
from peft import AutoPeftModelForQuestionAnswering
|
3 |
from huggingface_hub import login
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
tokenizer = AutoTokenizer.from_pretrained("./model_output")
|
11 |
-
|
12 |
-
# Push to Hub
|
13 |
-
model_name = "AvocadoMuffin/roberta-cuad-qa" # or whatever name you want
|
14 |
-
model.push_to_hub(model_name)
|
15 |
-
tokenizer.push_to_hub(model_name)
|
16 |
-
|
17 |
-
print(f"β
Model pushed to: https://huggingface.co/{model_name}")
|
|
|
1 |
+
import os
|
2 |
from transformers import AutoTokenizer
|
3 |
from peft import AutoPeftModelForQuestionAnswering
|
4 |
from huggingface_hub import login
|
5 |
|
6 |
+
def main():
|
7 |
+
# Get token from environment (using your existing roberta_token)
|
8 |
+
hf_token = os.environ.get('roberta_token')
|
9 |
+
|
10 |
+
if not hf_token:
|
11 |
+
print("β roberta_token not found in environment!")
|
12 |
+
print("Make sure roberta_token is set in your Space secrets.")
|
13 |
+
return
|
14 |
+
|
15 |
+
try:
|
16 |
+
print("π Logging into Hugging Face Hub...")
|
17 |
+
login(token=hf_token)
|
18 |
+
print("β
Login successful!")
|
19 |
+
|
20 |
+
print("π Loading trained model from ./model_output...")
|
21 |
+
# Check if model exists
|
22 |
+
if not os.path.exists("./model_output"):
|
23 |
+
print("β ./model_output directory not found!")
|
24 |
+
print("Make sure you've run training first.")
|
25 |
+
return
|
26 |
+
|
27 |
+
# Load your already-trained model
|
28 |
+
model = AutoPeftModelForQuestionAnswering.from_pretrained("./model_output")
|
29 |
+
tokenizer = AutoTokenizer.from_pretrained("./model_output")
|
30 |
+
print("β
Model loaded successfully!")
|
31 |
+
|
32 |
+
# Push to Hub
|
33 |
+
model_name = "AvocadoMuffin/roberta-cuad-qa"
|
34 |
+
print(f"β¬οΈ Pushing model to Hub: {model_name}")
|
35 |
+
|
36 |
+
model.push_to_hub(model_name, private=False)
|
37 |
+
tokenizer.push_to_hub(model_name, private=False)
|
38 |
+
|
39 |
+
print(f"π SUCCESS! Model pushed to: https://huggingface.co/{model_name}")
|
40 |
+
|
41 |
+
# Also push training info if it exists
|
42 |
+
training_info_path = "./model_output/training_info.json"
|
43 |
+
if os.path.exists(training_info_path):
|
44 |
+
from huggingface_hub import upload_file
|
45 |
+
upload_file(
|
46 |
+
path_or_fileobj=training_info_path,
|
47 |
+
path_in_repo="training_info.json",
|
48 |
+
repo_id=model_name,
|
49 |
+
repo_type="model"
|
50 |
+
)
|
51 |
+
print("π Training info also uploaded!")
|
52 |
+
|
53 |
+
except Exception as e:
|
54 |
+
print(f"β Error: {str(e)}")
|
55 |
+
print("Common issues:")
|
56 |
+
print("- Invalid token")
|
57 |
+
print("- Model name already exists (try a different name)")
|
58 |
+
print("- Network issues")
|
59 |
|
60 |
+
if __name__ == "__main__":
|
61 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|