hmusman2804045-max commited on
Commit
58b3cf9
Β·
1 Parent(s): babcc93

Update custom domain to urdu-sentiment.hmuhammadusman.com

Browse files
Files changed (2) hide show
  1. README.md +2 -2
  2. modal_app.py +24 -33
README.md CHANGED
@@ -3,7 +3,7 @@
3
  Welcome to the Urdu Sentiment and Emotion Analysis Engine project! This repository contains the code for a multilingual NLP system that classifies sentiment (Positive, Negative, Neutral) and emotion (Joy, Anger, Fear, Sadness) from Urdu, Roman Urdu, and mixed-language text using a fine-tuned XLM-RoBERTa transformer.
4
 
5
  ## Current Progress: Phase 9 (Modal.com Deployment β€” In Progress)
6
- The project has successfully completed Phases 1 through 8. The AI models are fully trained, uploaded to Hugging Face Hub (`usman-ai-dev/urdu-sentiment-xlmr` & `usman-ai-dev/urdu-emotion-xlmr`), and integrated into a production-ready **FastAPI** web server with Uvicorn. The frontend features a dark-mode Glassmorphism dashboard with an interactive 3D WebGL Three.js particle wave background, floating ambient glowing orbs, real-time cursor spotlight, Chart.js analytics, and automated live tweet feed streaming. Phase 9 deploys the full stack to **Modal.com** with a custom domain (`urdu-ai.hmuhammadusman.com`).
7
 
8
  ### Repository Structure
9
  - `app.py`: FastAPI Web Server exposing all REST API routes (`/analyze`, `/analytics`, `/detect-language`, `/live-feed`, `/health`).
@@ -67,5 +67,5 @@ The server will boot up and listen on `http://127.0.0.1:5000`.
67
  - **Phase 8** βœ…: Models pushed to Hugging Face Hub. `predictor.py` updated to load from Hub.
68
  - **Phase 9**: Deploy full FastAPI stack to **Modal.com** (free $30/month credit tier).
69
  - Run: `modal deploy modal_app.py`
70
- - Custom domain: `urdu-ai.hmuhammadusman.com`
71
  - GitHub Actions auto-deploys on every push to `main`.
 
3
  Welcome to the Urdu Sentiment and Emotion Analysis Engine project! This repository contains the code for a multilingual NLP system that classifies sentiment (Positive, Negative, Neutral) and emotion (Joy, Anger, Fear, Sadness) from Urdu, Roman Urdu, and mixed-language text using a fine-tuned XLM-RoBERTa transformer.
4
 
5
  ## Current Progress: Phase 9 (Modal.com Deployment β€” In Progress)
6
+ The project has successfully completed Phases 1 through 8. The AI models are fully trained, uploaded to Hugging Face Hub (`usman-ai-dev/urdu-sentiment-xlmr` & `usman-ai-dev/urdu-emotion-xlmr`), and integrated into a production-ready **FastAPI** web server with Uvicorn. The frontend features a dark-mode Glassmorphism dashboard with an interactive 3D WebGL Three.js particle wave background, floating ambient glowing orbs, real-time cursor spotlight, Chart.js analytics, and automated live tweet feed streaming. Phase 9 deploys the full stack to **Modal.com** with a custom domain (`urdu-sentiment.hmuhammadusman.com`).
7
 
8
  ### Repository Structure
9
  - `app.py`: FastAPI Web Server exposing all REST API routes (`/analyze`, `/analytics`, `/detect-language`, `/live-feed`, `/health`).
 
67
  - **Phase 8** βœ…: Models pushed to Hugging Face Hub. `predictor.py` updated to load from Hub.
68
  - **Phase 9**: Deploy full FastAPI stack to **Modal.com** (free $30/month credit tier).
69
  - Run: `modal deploy modal_app.py`
70
+ - Custom domain: `urdu-sentiment.hmuhammadusman.com`
71
  - GitHub Actions auto-deploys on every push to `main`.
modal_app.py CHANGED
@@ -1,19 +1,20 @@
1
  """
2
- modal_app.py β€” Phase 9: Modal.com Deployment Entrypoint
3
- ---------------------------------------------------------
4
- Wraps the existing FastAPI app (app.py) for serverless deployment
5
- on Modal.com with custom domain support.
6
-
7
- Deploy command:
8
- modal deploy modal_app.py
9
-
10
- Local test command:
11
- modal serve modal_app.py
12
  """
13
 
14
  import modal
15
 
16
- # ── Docker image with all dependencies ────────────────────────────────────────
 
 
 
 
 
 
 
17
  image = (
18
  modal.Image.debian_slim(python_version="3.10")
19
  .pip_install(
@@ -28,38 +29,28 @@ image = (
28
  "scikit-learn==1.4.0",
29
  "accelerate==0.29.0",
30
  )
 
 
 
 
 
 
 
31
  )
32
 
33
- # ── Modal app definition ───────────────────────────────────────────────────────
34
  app = modal.App("urdu-sentiment-engine", image=image)
35
 
36
- # ── Mount local project files into the container ──────────────────────────────
37
- project_mount = modal.Mount.from_local_dir(
38
- ".",
39
- remote_path="/app",
40
- # Exclude large/unnecessary directories
41
- condition=lambda path: not any(
42
- part in path for part in [
43
- "models", "urdu_env", "__pycache__", ".git",
44
- "data", "logs", "results", "training", "evaluation",
45
- ".github", "kaggle_upload.zip",
46
- ]
47
- ),
48
- )
49
 
50
  @app.function(
51
- mounts=[project_mount],
52
- # Keeps one container warm to avoid cold starts on the first request
53
- min_containers=1,
54
- # Give enough CPU/memory for the two XLM-RoBERTa models (~4GB RAM)
55
- memory=4096,
56
  cpu=2.0,
57
- # Models download from HF Hub on first cold-start then are cached
58
- timeout=300,
59
  )
60
  @modal.asgi_app()
61
  def fastapi_app():
62
  import sys
63
  sys.path.insert(0, "/app")
64
- from app import app as _app # Import the existing FastAPI app
65
  return _app
 
1
  """
2
+ modal_app.py β€” Phase 9: Modal.com Deployment (Modal v1.5+)
3
+ ------------------------------------------------------------
4
+ Deploy: python -m modal deploy modal_app.py
5
+ Test: python -m modal serve modal_app.py
 
 
 
 
 
 
6
  """
7
 
8
  import modal
9
 
10
+ # ── Source files to include (explicit list β€” no large dirs) ───────────────────
11
+ SOURCE_FILES = [
12
+ "app.py",
13
+ "predictor.py",
14
+ "lang_detector.py",
15
+ ]
16
+
17
+ # ── Build container image ─────────────────────────────────────────────────────
18
  image = (
19
  modal.Image.debian_slim(python_version="3.10")
20
  .pip_install(
 
29
  "scikit-learn==1.4.0",
30
  "accelerate==0.29.0",
31
  )
32
+ # Copy only the essential Python source files (not models/, urdu_env/, etc.)
33
+ .add_local_file("app.py", remote_path="/app/app.py")
34
+ .add_local_file("predictor.py", remote_path="/app/predictor.py")
35
+ .add_local_file("lang_detector.py",remote_path="/app/lang_detector.py")
36
+ # Copy frontend assets
37
+ .add_local_dir("templates", remote_path="/app/templates")
38
+ .add_local_dir("static", remote_path="/app/static")
39
  )
40
 
41
+ # ── Modal app ─────────────────────────────────────────────────────────────────
42
  app = modal.App("urdu-sentiment-engine", image=image)
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  @app.function(
46
+ min_containers=1, # Keep one warm to avoid cold starts
47
+ memory=4096, # 4GB RAM for two XLM-RoBERTa models (~2.2GB)
 
 
 
48
  cpu=2.0,
49
+ timeout=300, # Allow 5min on cold start for model download from HF Hub
 
50
  )
51
  @modal.asgi_app()
52
  def fastapi_app():
53
  import sys
54
  sys.path.insert(0, "/app")
55
+ from app import app as _app
56
  return _app