chatbot-mimic-notes / deploy_to_huggingface.py
Jesse Liu
update files
c26f5b3
#!/usr/bin/env python3
"""
Script to deploy the Patient Evaluation App to Hugging Face Spaces for permanent hosting.
This will give you a permanent URL that doesn't expire.
"""
import os
import subprocess
import sys
def check_requirements():
"""Check if required packages are installed"""
try:
import gradio
print("βœ… Gradio is installed")
except ImportError:
print("❌ Gradio not found. Please install with: pip install gradio")
return False
try:
subprocess.run(["huggingface-cli", "--help"], capture_output=True, check=True)
print("βœ… Hugging Face CLI is available")
except (subprocess.CalledProcessError, FileNotFoundError):
print("❌ Hugging Face CLI not found. Please install with: pip install huggingface_hub[cli]")
return False
return True
def check_login():
"""Check if user is logged into Hugging Face"""
try:
result = subprocess.run(["huggingface-cli", "whoami"], capture_output=True, text=True)
if result.returncode == 0:
print(f"βœ… Logged in as: {result.stdout.strip()}")
return True
else:
print("❌ Not logged into Hugging Face")
return False
except Exception as e:
print(f"❌ Error checking login status: {e}")
return False
def create_space_config():
"""Create the space configuration file"""
config_content = """---
title: Patient Evaluation System
emoji: πŸ₯
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 3.50.2
app_file: chatgpt.py
pinned: false
license: mit
---
# Patient Evaluation System
A comprehensive system for medical experts to evaluate AI-generated patient summaries.
## Features
- Multi-admission patient data evaluation
- Simplified comment system
- Google Drive integration for data backup
- Real-time statistics and analytics
- CSV/JSON data export
## Usage
1. Select a patient sample from the evaluation tab
2. Review the AI-generated summary against the original data
3. Provide ratings and feedback
4. Submit evaluation for analysis
## Setup
The application will guide you through any necessary setup steps.
"""
with open("README.md", "w") as f:
f.write(config_content)
print("βœ… Created README.md for Hugging Face Space")
def deploy():
"""Deploy to Hugging Face Spaces"""
if not check_requirements():
return False
if not check_login():
print("\nπŸ”‘ Please login to Hugging Face first:")
print("Run: huggingface-cli login")
print("Then run this script again.")
return False
print("\nπŸš€ Starting deployment to Hugging Face Spaces...")
# Create space config
create_space_config()
try:
# Deploy using gradio
print("πŸ“€ Deploying application...")
result = subprocess.run(["gradio", "deploy", "--hf-token"],
input="y\n", text=True, capture_output=True)
if result.returncode == 0:
print("βœ… Deployment successful!")
print("\n🌐 Your permanent URL will be:")
print("https://your-username-patient-evaluation.hf.space")
print("\nπŸ’‘ Tips:")
print("- The URL will be permanent and won't expire")
print("- You can update the app by running this script again")
print("- Your Google Drive data will be preserved")
return True
else:
print(f"❌ Deployment failed: {result.stderr}")
return False
except Exception as e:
print(f"❌ Error during deployment: {e}")
return False
def main():
print("πŸ₯ Patient Evaluation System - Hugging Face Deployment")
print("=" * 60)
print("\nπŸ“‹ This script will deploy your app to Hugging Face Spaces")
print("Benefits:")
print("- βœ… Permanent URL (no 72-hour expiry)")
print("- βœ… Free hosting")
print("- βœ… HTTPS security")
print("- βœ… Easy updates")
answer = input("\n❓ Do you want to proceed? (y/n): ").lower().strip()
if answer in ['y', 'yes']:
if deploy():
print("\nπŸŽ‰ Deployment completed successfully!")
else:
print("\n😞 Deployment failed. Please check the errors above.")
else:
print("πŸ‘‹ Deployment cancelled.")
if __name__ == "__main__":
main()