File size: 4,565 Bytes
7d3d63c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | #!/usr/bin/env python3
"""
Upload Bengali AI model to Hugging Face Hub
Repository: megharudushi/Sheikh
"""
import os
from huggingface_hub import HfApi, create_repo, upload_folder
from huggingface_hub.utils import RepositoryNotFoundError
def upload_model_to_hf():
"""Upload the Bengali AI model to Hugging Face"""
print("🚀 Uploading Bengali AI to Hugging Face Hub...")
print("=" * 50)
# Initialize Hugging Face API
api = HfApi()
# Repository details
repo_id = "megharudushi/Sheikh"
local_dir = "./ready_bengali_ai"
# Check if local directory exists
if not os.path.exists(local_dir):
print(f"❌ Error: Directory {local_dir} not found!")
return False
try:
# Login prompt
print("📝 Please login to Hugging Face Hub")
print("This will open your browser for authentication...")
# Login (this will prompt for token)
api.login()
print(f"🔗 Creating repository: {repo_id}")
# Create repository
try:
repo_url = create_repo(
repo_id=repo_id,
exist_ok=True,
repo_type="model"
)
print(f"✅ Repository created/accessed: {repo_url}")
except Exception as e:
print(f"⚠️ Repository creation issue: {e}")
print("Continuing with upload...")
print(f"📤 Uploading model files from {local_dir}...")
# Upload all files
upload_folder(
folder_path=local_dir,
repo_id=repo_id,
commit_message="Upload complete Bengali AI model with tokenizer and config"
)
print("🎉 Model uploaded successfully!")
print(f"🌐 View your model at: https://huggingface.co/{repo_id}")
# Show repository info
print("\n📊 Repository Information:")
print(f" Repository ID: {repo_id}")
print(f" Local files: {len(os.listdir(local_dir))} files")
print(f" Model size: {os.path.getsize(f'{local_dir}/model.bin') / (1024*1024*1024):.2f} GB")
return True
except Exception as e:
print(f"❌ Upload failed: {e}")
print("\n🔧 Troubleshooting:")
print("1. Make sure you're logged in to Hugging Face")
print("2. Check your internet connection")
print("3. Verify repository permissions")
return False
def create_model_card():
"""Create a model card for the repository"""
model_card = """# Bengali AI Model
## Model Description
This is a Bengali (Bangla) language AI model trained on instruction-following datasets. The model can understand and respond to Bengali text queries.
## Model Details
- **Base Model**: microsoft/DialoGPT-medium
- **Language**: Bengali (Bangla)
- **Parameters**: 355M
- **Training Data**: Alpaca Bangla dataset
- **Model Size**: 1.4GB
## Usage
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load model
tokenizer = AutoTokenizer.from_pretrained("megharudushi/Sheikh")
model = AutoModelForCausalLM.from_pretrained("megharudushi/Sheikh")
# Generate response
input_text = "বাংলাদেশের রাজধানী কী?"
inputs = tokenizer.encode(input_text, return_tensors="pt")
outputs = model.generate(inputs, max_length=150, temperature=0.8)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```
## Training Details
- Trained on Bengali instruction-following data
- Fine-tuned for educational and general knowledge queries
- Supports Bengali language understanding and generation
## License
Please check the repository for license information.
## Citation
If you use this model in your research, please cite the original base model and dataset sources.
"""
with open("./ready_bengali_ai/README.md", "w", encoding="utf-8") as f:
f.write(model_card)
print("📄 Created model card (README.md)")
if __name__ == "__main__":
print("🇧🇩 BANGLI AI HUGGING FACE UPLOAD")
print("=" * 40)
# Create model card
create_model_card()
# Upload to Hugging Face
success = upload_model_to_hf()
if success:
print("\n🎉 UPLOAD COMPLETE!")
print("Your Bengali AI model is now live on Hugging Face Hub!")
print("Repository: https://huggingface.co/megharudushi/Sheikh")
else:
print("\n❌ Upload failed. Please check the error messages above.") |