Spaces:
Running
Running
initial commit
Browse files- .gitignore +2 -0
- Dockerfile +17 -0
- README.md +4 -6
- app/main.py +49 -0
- app/utils.py +46 -0
- params.cfg +1 -0
- requirements.txt +8 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
*.DS_Store
|
Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# pick your favorite slim Python base
|
2 |
+
FROM python:3.10-slim
|
3 |
+
|
4 |
+
WORKDIR /app
|
5 |
+
|
6 |
+
# install dependencies
|
7 |
+
COPY requirements.txt .
|
8 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
9 |
+
|
10 |
+
# copy app
|
11 |
+
COPY app.py .
|
12 |
+
|
13 |
+
# expose Gradio default port
|
14 |
+
EXPOSE 7860
|
15 |
+
|
16 |
+
# launch
|
17 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
-
license: mit
|
9 |
---
|
10 |
|
11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: ChatFed Orchestrator
|
3 |
+
emoji: 🐠
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: pink
|
6 |
sdk: docker
|
7 |
pinned: false
|
|
|
8 |
---
|
9 |
|
|
app/main.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
from langgraph import Graph, NodeFunction
|
4 |
+
|
5 |
+
# node 1: call your retriever
|
6 |
+
def retrieve_node(query: str):
|
7 |
+
client = Client("giz/chatfed_retriever") # HF repo name
|
8 |
+
return client.predict(
|
9 |
+
query=query,
|
10 |
+
reports_filter="",
|
11 |
+
sources_filter="",
|
12 |
+
subtype_filter="",
|
13 |
+
year_filter="",
|
14 |
+
api_name="/retrieve"
|
15 |
+
)
|
16 |
+
|
17 |
+
# node 2: call your generator
|
18 |
+
def generate_node(query: str, context: str):
|
19 |
+
client = Client("giz/chatfed_generator")
|
20 |
+
return client.predict(
|
21 |
+
query=query,
|
22 |
+
context=context,
|
23 |
+
api_name="/generate"
|
24 |
+
)
|
25 |
+
|
26 |
+
# build the graph
|
27 |
+
graph = Graph()
|
28 |
+
n1 = graph.add_node(NodeFunction(retrieve_node), name="retrieve")
|
29 |
+
n2 = graph.add_node(NodeFunction(generate_node), name="generate")
|
30 |
+
graph.link(n1, n2)
|
31 |
+
|
32 |
+
# expose a simple Gradio interface that drives the graph
|
33 |
+
def pipeline(query: str):
|
34 |
+
# run the graph: pass query into retrieve, then into generate
|
35 |
+
result = graph.run({
|
36 |
+
"retrieve": {"query": query}
|
37 |
+
})
|
38 |
+
return result["generate"]
|
39 |
+
|
40 |
+
iface = gr.Interface(
|
41 |
+
fn=pipeline,
|
42 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
43 |
+
outputs="text",
|
44 |
+
title="Modular RAG Pipeline",
|
45 |
+
)
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
# when HF spins up your container it will pick up port 7860 by default
|
49 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
app/utils.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import configparser
|
2 |
+
import logging
|
3 |
+
import os
|
4 |
+
import ast
|
5 |
+
import re
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
# Local .env file
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
def getconfig(configfile_path: str):
|
12 |
+
"""
|
13 |
+
Read the config file
|
14 |
+
Params
|
15 |
+
----------------
|
16 |
+
configfile_path: file path of .cfg file
|
17 |
+
"""
|
18 |
+
config = configparser.ConfigParser()
|
19 |
+
try:
|
20 |
+
config.read_file(open(configfile_path))
|
21 |
+
return config
|
22 |
+
except:
|
23 |
+
logging.warning("config file not found")
|
24 |
+
|
25 |
+
|
26 |
+
def get_auth(provider: str) -> dict:
|
27 |
+
"""Get authentication configuration for different providers"""
|
28 |
+
auth_configs = {
|
29 |
+
"huggingface": {"api_key": os.getenv("HF_TOKEN")},
|
30 |
+
"qdrant": {"api_key": os.getenv("QDRANT_API_KEY")},
|
31 |
+
}
|
32 |
+
|
33 |
+
provider = provider.lower() # Normalize to lowercase
|
34 |
+
|
35 |
+
if provider not in auth_configs:
|
36 |
+
raise ValueError(f"Unsupported provider: {provider}")
|
37 |
+
|
38 |
+
auth_config = auth_configs[provider]
|
39 |
+
api_key = auth_config.get("api_key")
|
40 |
+
|
41 |
+
if not api_key:
|
42 |
+
logging.warning(f"No API key found for provider '{provider}'. Please set the appropriate environment variable.")
|
43 |
+
auth_config["api_key"] = None
|
44 |
+
|
45 |
+
return auth_config
|
46 |
+
|
params.cfg
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
langchain
|
3 |
+
langchain-community
|
4 |
+
qdrant-client
|
5 |
+
sentence-transformers
|
6 |
+
gradio_client>=0.10.0
|
7 |
+
huggingface_hub>=0.20.0
|
8 |
+
torch
|