Spaces:
Running
Running
File size: 3,639 Bytes
44b5c36 |
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 |
#!/usr/bin/env python3
"""
Setup and run script for the llama.cpp Hugging Face Space
"""
import subprocess
import sys
import os
def install_dependencies():
"""Install required dependencies"""
print("π¦ Installing dependencies...")
try:
# Upgrade pip first
subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "pip"], check=True)
# Install requirements
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True)
print("β
Dependencies installed successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"β Error installing dependencies: {e}")
return False
def test_installation():
"""Test if llama.cpp is properly installed"""
print("π§ͺ Testing llama.cpp installation...")
try:
# Test import
subprocess.run([sys.executable, "-c", "from llama_cpp import Llama; print('β
llama-cpp-python imported successfully')"], check=True)
# Test other dependencies
test_imports = [
"import gradio; print('β
Gradio imported')",
"import huggingface_hub; print('β
Hugging Face Hub imported')",
"from config import get_recommended_model; print('β
Config imported')"
]
for test_import in test_imports:
subprocess.run([sys.executable, "-c", test_import], check=True)
print("β
All tests passed!")
return True
except subprocess.CalledProcessError as e:
print(f"β Installation test failed: {e}")
return False
def run_app():
"""Run the Gradio app"""
print("π Starting the Gradio app...")
print("π Note: The Osmosis model will be downloaded on first use")
print("π The app will be available at http://localhost:7860")
print("βΉοΈ Press Ctrl+C to stop the app")
try:
subprocess.run([sys.executable, "app.py"], check=True)
except KeyboardInterrupt:
print("\nπ App stopped by user")
except subprocess.CalledProcessError as e:
print(f"β Error running app: {e}")
def main():
"""Main setup function"""
print("π§ llama.cpp Hugging Face Space Setup")
print("=" * 50)
# Check Python version
if sys.version_info < (3, 8):
print("β Python 3.8 or higher is required")
sys.exit(1)
print(f"β
Python version: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
# Install dependencies
if not install_dependencies():
print("β Failed to install dependencies")
sys.exit(1)
# Test installation
if not test_installation():
print("β Installation test failed")
sys.exit(1)
print("\nπ Setup completed successfully!")
print("\nπ What's installed:")
print(" - llama-cpp-python for efficient CPU inference")
print(" - Gradio for the web interface")
print(" - Hugging Face Hub for model downloading")
print(" - Osmosis Structure 0.6B model (will download on first use)")
# Ask if user wants to run the app
print("\nβ Would you like to run the app now? (y/n): ", end="")
try:
response = input().lower().strip()
if response in ['y', 'yes']:
run_app()
else:
print("π Setup complete! Run 'python app.py' when ready.")
except (EOFError, KeyboardInterrupt):
print("\nπ Setup complete! Run 'python app.py' when ready.")
if __name__ == "__main__":
main() |