Sheikh / upload_to_huggingface.py
megharudushi's picture
Upload folder using huggingface_hub
7d3d63c verified
#!/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.")