DhruvSoni commited on
Commit
e881355
Β·
1 Parent(s): 36d6e26

feat: Add FastAPI deployment files, Dockerfile, and Hugging Face sync GitHub Action

Browse files
Files changed (6) hide show
  1. .dockerignore +6 -0
  2. .github/workflows/hf_sync.yml +22 -0
  3. Dockerfile +7 -0
  4. app.py +76 -0
  5. main.py +43 -0
  6. requirement.txt +2 -1
.dockerignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .env
5
+ .git
6
+ .gitignore
.github/workflows/hf_sync.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face Space
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ sync-to-hub:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout repository
13
+ uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+
18
+ - name: Push to HF
19
+ env:
20
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
21
+ run: |
22
+ git push --force https://Dhruvsoni4125:$HF_TOKEN@huggingface.co/spaces/Dhruvsoni4125/Multi-Agent-Rag-System main
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+ WORKDIR /code
3
+ COPY ./requirement.txt /code/requirements.txt
4
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
5
+ COPY . .
6
+ # Hugging Face runs on port 7860 by default
7
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from pipeline import run_research_pipeline
4
+ from dotenv import load_dotenv
5
+
6
+ # Load local environment variables if present
7
+ load_dotenv()
8
+
9
+ # Map Gemini_API_KEY to GOOGLE_API_KEY for LangChain if necessary
10
+ if "Gemini_API_KEY" in os.environ and "GOOGLE_API_KEY" not in os.environ:
11
+ os.environ["GOOGLE_API_KEY"] = os.environ["Gemini_API_KEY"]
12
+
13
+ st.set_page_config(
14
+ page_title="Multi-Agent Research Assistant",
15
+ page_icon="πŸ€–",
16
+ layout="wide"
17
+ )
18
+
19
+ # Custom Styling
20
+ st.markdown("""
21
+ <style>
22
+ .main-title {
23
+ font-size: 3rem;
24
+ font-weight: 700;
25
+ color: #1E3A8A;
26
+ margin-bottom: 0.5rem;
27
+ }
28
+ .subtitle {
29
+ font-size: 1.2rem;
30
+ color: #4B5563;
31
+ margin-bottom: 2rem;
32
+ }
33
+ </style>
34
+ """, unsafe_allow_html=True)
35
+
36
+ st.markdown('<div class="main-title">πŸ€– Multi-Agent RAG Research Assistant</div>', unsafe_allow_html=True)
37
+ st.markdown('<div class="subtitle">Enter a topic. The system will search the web, scrape articles, compile a report, and critique it.</div>', unsafe_allow_html=True)
38
+
39
+ topic = st.text_input("What would you like to research?", placeholder="e.g., Advancements in Quantum Computing")
40
+
41
+ if st.button("Start Agent Collaboration", type="primary"):
42
+ if not topic.strip():
43
+ st.error("Please enter a research topic first.")
44
+ else:
45
+ # Visual collaboration status
46
+ with st.status("Agents are collaborating...", expanded=True) as status_box:
47
+ st.write("πŸ” Search Agent: Searching the web via Tavily...")
48
+
49
+ # Run the research pipeline
50
+ try:
51
+ result = run_research_pipeline(topic)
52
+ status_box.update(label="Research Complete!", state="complete", expanded=False)
53
+ st.success("Research completed successfully!")
54
+
55
+ # Show results in nice clean tabs
56
+ tab1, tab2, tab3 = st.tabs(["πŸ“„ Final Report", "⭐ Critic Review", "πŸ”§ Technical Data"])
57
+
58
+ with tab1:
59
+ st.markdown("### Drafted Report")
60
+ st.markdown(result.get("report", "No report generated."))
61
+
62
+ with tab2:
63
+ st.markdown("### Critic Score and Feedback")
64
+ st.markdown(result.get("feedback", "No feedback generated."))
65
+
66
+ with tab3:
67
+ col1, col2 = st.columns(2)
68
+ with col1:
69
+ st.subheader("Web Search Output")
70
+ st.code(result.get("search_results", "None"))
71
+ with col2:
72
+ st.subheader("Scraped Content Summary")
73
+ st.code(result.get("scraped_content", "None"))
74
+ except Exception as e:
75
+ status_box.update(label="Pipeline Failed", state="error")
76
+ st.error(f"Error executing pipeline: {str(e)}")
main.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI, HTTPException
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+ from pydantic import BaseModel
5
+ from pipeline import run_research_pipeline
6
+ from dotenv import load_dotenv
7
+
8
+ load_dotenv()
9
+
10
+ # Map Gemini_API_KEY to GOOGLE_API_KEY for LangChain if necessary
11
+ if "Gemini_API_KEY" in os.environ and "GOOGLE_API_KEY" not in os.environ:
12
+ os.environ["GOOGLE_API_KEY"] = os.environ["Gemini_API_KEY"]
13
+
14
+ app = FastAPI(
15
+ title="Multi-Agent RAG System API",
16
+ description="REST API for the multi-agent research pipeline.",
17
+ version="1.0.0"
18
+ )
19
+
20
+ # Enable CORS for frontend integration
21
+ app.add_middleware(
22
+ CORSMiddleware,
23
+ allow_origins=["*"],
24
+ allow_credentials=True,
25
+ allow_methods=["*"],
26
+ allow_headers=["*"],
27
+ )
28
+
29
+ class ResearchRequest(BaseModel):
30
+ topic: str
31
+
32
+ @app.get("/")
33
+ def home():
34
+ return {"status": "online", "docs": "/docs"}
35
+
36
+ @app.post("/research")
37
+ def research(request: ResearchRequest):
38
+ if not request.topic.strip():
39
+ raise HTTPException(status_code=400, detail="Topic is empty")
40
+ try:
41
+ return run_research_pipeline(request.topic)
42
+ except Exception as e:
43
+ raise HTTPException(status_code=500, detail=str(e))
requirement.txt CHANGED
@@ -20,4 +20,5 @@ fastapi
20
  uvicorn
21
 
22
  langsmith
23
- pytest
 
 
20
  uvicorn
21
 
22
  langsmith
23
+ pytest
24
+ streamlit