Spaces:
Runtime error
Runtime error
Delete run.py
Browse files
run.py
DELETED
@@ -1,90 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Visual Question Answering Application - Run Script for Streamlit
|
3 |
-
"""
|
4 |
-
|
5 |
-
import os
|
6 |
-
import subprocess
|
7 |
-
import sys
|
8 |
-
|
9 |
-
# Configure minimal environment settings
|
10 |
-
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # Suppress TensorFlow logging
|
11 |
-
|
12 |
-
|
13 |
-
def check_requirements_installed():
|
14 |
-
"""Check if requirements are installed"""
|
15 |
-
try:
|
16 |
-
import streamlit
|
17 |
-
import torch
|
18 |
-
import transformers
|
19 |
-
from PIL import Image
|
20 |
-
|
21 |
-
return True
|
22 |
-
except ImportError as e:
|
23 |
-
print(f"Error: Required package not installed - {e}")
|
24 |
-
print("Please install requirements using: pip install -r requirements.txt")
|
25 |
-
return False
|
26 |
-
|
27 |
-
|
28 |
-
def ensure_directories():
|
29 |
-
"""Ensure all required directories exist"""
|
30 |
-
# Get the base directory
|
31 |
-
base_dir = os.path.dirname(os.path.abspath(__file__))
|
32 |
-
|
33 |
-
# Create uploads directory
|
34 |
-
uploads_dir = os.path.join(base_dir, "static", "uploads")
|
35 |
-
os.makedirs(uploads_dir, exist_ok=True)
|
36 |
-
print(f"Uploads directory: {uploads_dir}")
|
37 |
-
|
38 |
-
# Create logs directory
|
39 |
-
logs_dir = os.path.join(base_dir, "logs")
|
40 |
-
os.makedirs(logs_dir, exist_ok=True)
|
41 |
-
|
42 |
-
|
43 |
-
def main():
|
44 |
-
"""Main function to run the application"""
|
45 |
-
print("Visual Question Answering - Multi-Modal AI Application with Streamlit")
|
46 |
-
|
47 |
-
# Check requirements
|
48 |
-
if not check_requirements_installed():
|
49 |
-
sys.exit(1)
|
50 |
-
|
51 |
-
# Ensure directories exist
|
52 |
-
ensure_directories()
|
53 |
-
|
54 |
-
# Set environment variables
|
55 |
-
os.environ["VQA_MODEL"] = os.environ.get(
|
56 |
-
"VQA_MODEL", "blip"
|
57 |
-
) # Default to 'blip' model
|
58 |
-
|
59 |
-
# Get the app.py path
|
60 |
-
app_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "app.py")
|
61 |
-
if not os.path.exists(app_path):
|
62 |
-
print(f"Error: Streamlit app not found at {app_path}")
|
63 |
-
sys.exit(1)
|
64 |
-
|
65 |
-
# Print startup information
|
66 |
-
port = int(os.environ.get("PORT", 7860)) # Set default port to 7860 for Hugging Face
|
67 |
-
print(f"Starting VQA application on http://localhost:{port}")
|
68 |
-
print(f"Using VQA model: {os.environ.get('VQA_MODEL', 'blip')}")
|
69 |
-
print("Press Ctrl+C to exit")
|
70 |
-
|
71 |
-
# Run the Streamlit app
|
72 |
-
cmd = [
|
73 |
-
"streamlit",
|
74 |
-
"run",
|
75 |
-
app_path,
|
76 |
-
"--server.port",
|
77 |
-
str(port),
|
78 |
-
"--server.address",
|
79 |
-
"0.0.0.0",
|
80 |
-
]
|
81 |
-
try:
|
82 |
-
subprocess.run(cmd)
|
83 |
-
except KeyboardInterrupt:
|
84 |
-
print("\nShutting down the application...")
|
85 |
-
except Exception as e:
|
86 |
-
print(f"Error launching Streamlit: {e}")
|
87 |
-
|
88 |
-
|
89 |
-
if __name__ == "__main__":
|
90 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|