Tanuj commited on
Commit
eac7939
·
1 Parent(s): c8f17aa

Add modal app

Browse files
Files changed (1) hide show
  1. modal_app.py +67 -0
modal_app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import modal
2
+ from pathlib import Path
3
+ import sys
4
+
5
+ # Current directory path
6
+ src_dir = Path(__file__).parent / "src"
7
+ agent_dir = src_dir / "yt_agent"
8
+ gradio_dir = src_dir / "yt_gradio"
9
+ rag_dir = src_dir / "yt_rag"
10
+
11
+ # Create Modal image with required dependencies
12
+ web_image = modal.Image.debian_slim(python_version="3.10").pip_install(
13
+ "python-dotenv",
14
+ "fastapi[standard]==0.115.4",
15
+ "gradio[mcp]==5.33.0",
16
+ "requests",
17
+ "smolagents",
18
+ # Add any other dependencies you need
19
+ ).add_local_file(rag_dir / "rag.py", "/root/src/yt_rag/rag.py") \
20
+ .add_local_file(gradio_dir / "app.py", "/root/src/yt_gradio/app.py") \
21
+ .add_local_file(agent_dir / "agent.py", "/root/src/yt_agent/agent.py") \
22
+ .add_local_file(agent_dir / "prompts.py", "/root/src/yt_agent/prompts.py") \
23
+ .add_local_file(agent_dir / "tools.py", "/root/src/yt_agent/tools.py") \
24
+ .add_local_file(src_dir / "schemas.py", "/root/src/schemas.py")
25
+
26
+ app = modal.App("youtwo-gradio", image=web_image)
27
+
28
+ # Modal limits
29
+ MAX_CONCURRENT_USERS = 10
30
+ MINUTES = 60 # seconds
31
+ TIME_LIMIT = 10 * MINUTES # time limit (3540 seconds, just under the 3600s maximum)
32
+
33
+ # This volume will store any local files needed by the app
34
+ volume = modal.Volume.from_name("youtwo-volume", create_if_missing=True)
35
+
36
+ @app.function(
37
+ volumes={"/data": volume},
38
+ secrets=[
39
+ modal.Secret.from_name("vectara"),
40
+ modal.Secret.from_name("nebius")
41
+ ],
42
+ max_containers=1,
43
+ scaledown_window=TIME_LIMIT, # 3540 seconds, within the allowed 2-3600 second range
44
+ )
45
+ @modal.asgi_app()
46
+ def gradio_app():
47
+ from fastapi import FastAPI
48
+ from gradio.routes import mount_gradio_app
49
+
50
+ # Add /root to path for imports
51
+ sys.path.append("/root")
52
+
53
+ # Import RAG functions
54
+ # from rag import is_allowed_filetype, upload_file_to_vectara, retrieve_chunks
55
+ from src.yt_gradio.app import get_gradio_blocks
56
+
57
+ # ---------------------------
58
+ # Backend Functions
59
+ # ---------------------------
60
+
61
+ blocks = get_gradio_blocks() # Mount Gradio app to FastAPI for Modal
62
+ app = FastAPI()
63
+ return mount_gradio_app(app=app, blocks=blocks, path="/")
64
+
65
+
66
+ if __name__ == "__main__":
67
+ gradio_app.serve(mcp_server=True)