deasdutta commited on
Commit
72e55e1
·
verified ·
1 Parent(s): 2148df8

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """
3
+ Main application entry point for ContinuumAgent
4
+ Starts the FastAPI server and initializes all components
5
+ """
6
+
7
+ import os
8
+ import sys
9
+ import uvicorn
10
+ from huggingface_hub import hf_hub_download
11
+ from fastapi import FastAPI
12
+ from app.main import app as fastapi_app
13
+
14
+ def ensure_model_exists():
15
+ """
16
+ Ensure the GGUF model exists, download if needed
17
+
18
+ Returns:
19
+ Path to the model file
20
+ """
21
+ model_dir = "models/slow"
22
+ os.makedirs(model_dir, exist_ok=True)
23
+
24
+ # Look for existing model
25
+ model_files = [f for f in os.listdir(model_dir) if f.endswith(".gguf")]
26
+
27
+ if model_files:
28
+ model_path = os.path.join(model_dir, model_files[0])
29
+ print(f"Using existing model: {model_path}")
30
+ return model_path
31
+
32
+ # Download model
33
+ try:
34
+ print("Downloading Mistral-7B-Instruct model (quantized)...")
35
+ model_path = hf_hub_download(
36
+ repo_id="TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
37
+ filename="mistral-7b-instruct-v0.2.Q4_K_M.gguf",
38
+ local_dir=model_dir
39
+ )
40
+ print(f"Successfully downloaded model to: {model_path}")
41
+ return model_path
42
+ except Exception as e:
43
+ print(f"Error downloading model: {e}")
44
+ print("Please download the model manually and place it in the models/slow directory")
45
+ sys.exit(1)
46
+
47
+ def create_directory_structure():
48
+ """Create required directory structure"""
49
+ os.makedirs("models/slow", exist_ok=True)
50
+ os.makedirs("models/patches", exist_ok=True)
51
+ os.makedirs("models/registry", exist_ok=True)
52
+ os.makedirs("models/gates", exist_ok=True)
53
+ os.makedirs("data/wiki_edits", exist_ok=True)
54
+
55
+ def main():
56
+ """Main entry point"""
57
+ # Create directory structure
58
+ create_directory_structure()
59
+
60
+ # Ensure model exists
61
+ model_path = ensure_model_exists()
62
+
63
+ # Run server
64
+ host = os.environ.get("HOST", "0.0.0.0")
65
+ port = int(os.environ.get("PORT", "8000"))
66
+
67
+ print(f"Starting ContinuumAgent server on {host}:{port}")
68
+ uvicorn.run(fastapi_app, host=host, port=port)
69
+
70
+ if __name__ == "__main__":
71
+ main()