“Transcendental-Programmer”
commited on
Commit
·
f56e71d
1
Parent(s):
c3cc0a9
final commit
Browse files
Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
COPY . /code
|
| 7 |
+
|
| 8 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 9 |
+
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
|
| 12 |
+
CMD ["streamlit", "run", "app.py", "--server.address", "0.0.0.0", "--server.port", "7860"]
|
app.py
CHANGED
|
@@ -1,59 +1,42 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
|
|
|
| 3 |
import logging
|
| 4 |
-
from
|
| 5 |
-
translation_model,
|
| 6 |
-
sentiment_model,
|
| 7 |
-
routing_model,
|
| 8 |
-
job_model
|
| 9 |
-
)
|
| 10 |
|
| 11 |
# Configure logging
|
| 12 |
logging.basicConfig(
|
| 13 |
level=logging.INFO,
|
| 14 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 15 |
-
handlers=[
|
|
|
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
page_title="Hostel Management System",
|
| 21 |
-
page_icon="🏨",
|
| 22 |
-
layout="wide"
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
def main():
|
| 26 |
-
st.title("🏨 Hostel Management System")
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
"Select Service",
|
| 31 |
-
["Translation", "Sentiment Analysis", "Grievance Routing", "Job Recommendation"]
|
| 32 |
-
)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
user_message = st.text_area("Enter text to translate")
|
| 46 |
-
target_lang = st.selectbox("Select target language", ["English", "Spanish", "French", "German"])
|
| 47 |
|
| 48 |
-
|
| 49 |
-
if user_message:
|
| 50 |
-
result = translation_model.process_message({
|
| 51 |
-
"user_message": user_message,
|
| 52 |
-
"target_language": target_lang
|
| 53 |
-
})
|
| 54 |
-
st.success(result.get("translated_text", "Translation failed"))
|
| 55 |
|
| 56 |
-
#
|
|
|
|
| 57 |
|
| 58 |
-
if __name__ ==
|
| 59 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from flask import Flask, jsonify
|
| 3 |
+
from routes import api_bp, initialize_models
|
| 4 |
import logging
|
| 5 |
+
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Configure logging
|
| 8 |
logging.basicConfig(
|
| 9 |
level=logging.INFO,
|
| 10 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 11 |
+
handlers=[
|
| 12 |
+
logging.StreamHandler()
|
| 13 |
+
]
|
| 14 |
)
|
| 15 |
|
| 16 |
+
def create_app():
|
| 17 |
+
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# Initialize models on startup
|
| 20 |
+
initialize_models()
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Register blueprints
|
| 23 |
+
app.register_blueprint(api_bp, url_prefix='/api')
|
| 24 |
+
|
| 25 |
+
# Home route
|
| 26 |
+
@app.route('/')
|
| 27 |
+
def home():
|
| 28 |
+
return jsonify({
|
| 29 |
+
'status': 'online',
|
| 30 |
+
'timestamp': datetime.utcnow().isoformat(),
|
| 31 |
+
'message': 'Welcome to the Hostel Management API'
|
| 32 |
+
})
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
return app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# This is for both local and production
|
| 37 |
+
app = create_app()
|
| 38 |
|
| 39 |
+
if __name__ == '__main__':
|
| 40 |
+
# Use the port specified by Hugging Face Spaces
|
| 41 |
+
port = int(os.environ.get('PORT', 7860))
|
| 42 |
+
app.run(host='0.0.0.0', port=port)
|
routes.py
CHANGED
|
@@ -7,15 +7,28 @@ from datetime import datetime
|
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
-
# Initialize models
|
| 11 |
-
translation_model =
|
| 12 |
-
sentiment_model =
|
| 13 |
-
routing_model =
|
| 14 |
-
job_model =
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
+
# Initialize models lazily to prevent startup issues
|
| 11 |
+
translation_model = None
|
| 12 |
+
sentiment_model = None
|
| 13 |
+
routing_model = None
|
| 14 |
+
job_model = None
|
| 15 |
|
| 16 |
+
def initialize_models():
|
| 17 |
+
global translation_model, sentiment_model, routing_model, job_model
|
| 18 |
+
|
| 19 |
+
if translation_model is None:
|
| 20 |
+
translation_model = MultilingualTranslationModel()
|
| 21 |
+
if sentiment_model is None:
|
| 22 |
+
sentiment_model = SentimentAnalysisModel()
|
| 23 |
+
if routing_model is None:
|
| 24 |
+
routing_model = IntelligentRoutingModel()
|
| 25 |
+
try:
|
| 26 |
+
routing_model.load_model('models/intelligent_routing/saved_model/model.keras')
|
| 27 |
+
except Exception as e:
|
| 28 |
+
logger.warning(f"Could not load routing model: {str(e)}")
|
| 29 |
+
if job_model is None:
|
| 30 |
+
job_model = JobRecommendationModel()
|
| 31 |
+
try:
|
| 32 |
+
job_model.load_model('models/job_recommendation/saved_model/model.keras')
|
| 33 |
+
except Exception as e:
|
| 34 |
+
logger.warning(f"Could not load job model: {str(e)}")
|
space.yml
CHANGED
|
@@ -2,6 +2,6 @@ title: Hostel Management System
|
|
| 2 |
emoji: 🏨
|
| 3 |
colorFrom: blue
|
| 4 |
colorTo: green
|
| 5 |
-
sdk:
|
| 6 |
-
|
| 7 |
pinned: false
|
|
|
|
| 2 |
emoji: 🏨
|
| 3 |
colorFrom: blue
|
| 4 |
colorTo: green
|
| 5 |
+
sdk: docker
|
| 6 |
+
app_port: 7860
|
| 7 |
pinned: false
|