janar commited on
Commit
b63c216
β€’
2 Parent(s): edf2758 df41eed

Merge pull request #2 from Janarthanam/streamlit

Browse files
Files changed (6) hide show
  1. Dockerfile +11 -3
  2. README.md +4 -4
  3. api/db/vector_store.py +1 -1
  4. fe/app.py +25 -0
  5. requirements.txt +1 -1
  6. run.sh +8 -0
Dockerfile CHANGED
@@ -1,6 +1,12 @@
1
  # Use an official Python base image
2
  FROM python:3.10-slim
3
 
 
 
 
 
 
 
4
  # Set the working directory
5
  WORKDIR /app
6
 
@@ -11,14 +17,16 @@ COPY requirements.txt .
11
  RUN pip install --trusted-host pypi.python.org -r requirements.txt
12
 
13
  # Copy the rest of the application code into the container
14
- COPY api .
15
 
16
  # Expose the port the app runs on
17
- EXPOSE 8080
18
 
19
  #todo these keys are environment specific
20
  ENV OPENAI_API_KEY=zzz
21
  ENV QDRANT_URL="https://32f125d3-5ab1-4058-a10a-bd38a1ebd647.us-east-1-0.aws.cloud.qdrant.io"
22
  ENV STORE="QDRANT"
 
 
23
  # Start the application using Uvicorn
24
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
 
1
  # Use an official Python base image
2
  FROM python:3.10-slim
3
 
4
+ # Set up a new user named "user" with user ID 1000
5
+ RUN useradd -m -u 1000 user
6
+
7
+ # Switch to the "user" user
8
+ USER user
9
+
10
  # Set the working directory
11
  WORKDIR /app
12
 
 
17
  RUN pip install --trusted-host pypi.python.org -r requirements.txt
18
 
19
  # Copy the rest of the application code into the container
20
+ COPY --chown=user run.sh api fe .
21
 
22
  # Expose the port the app runs on
23
+ EXPOSE 8080 8501
24
 
25
  #todo these keys are environment specific
26
  ENV OPENAI_API_KEY=zzz
27
  ENV QDRANT_URL="https://32f125d3-5ab1-4058-a10a-bd38a1ebd647.us-east-1-0.aws.cloud.qdrant.io"
28
  ENV STORE="QDRANT"
29
+ ENV be_url="http://127.0.0.1:8080"
30
+
31
  # Start the application using Uvicorn
32
+ CMD ["/bin/sh", "./run.sh"]
README.md CHANGED
@@ -1,13 +1,13 @@
1
  ---
2
  title: Toypdf
3
  emoji: πŸ“‰
4
- colorFrom: pink
5
  colorTo: red
6
  sdk: docker
7
- app_port: 8080
8
  pinned: true
9
- models: ["gpt2"]
10
- datasets: ["oscar-corpus/OSCAR-2109"]
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Toypdf
3
  emoji: πŸ“‰
4
+ colorFrom: blue
5
  colorTo: red
6
  sdk: docker
7
+ app_port: 8501
8
  pinned: true
9
+ models: ["sentence-transformers/all-MiniLM-L6-v2"]
10
+ datasets: ["multi_nli"]
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
api/db/vector_store.py CHANGED
@@ -91,5 +91,5 @@ class QdrantVectorStore(Store):
91
  def list_collections(self) -> list[dict]:
92
  """ return a list of collections.
93
  """
94
- return [ c for i,c in enumerate(self.client.get_collections().collections)]
95
 
 
91
  def list_collections(self) -> list[dict]:
92
  """ return a list of collections.
93
  """
94
+ return [ c.dict() for i,c in enumerate(self.client.get_collections().collections)]
95
 
fe/app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+
4
+ import streamlit as st
5
+
6
+ BE = os.getenv("be_url")
7
+
8
+
9
+ datasets = requests.get(f"{BE}/v1/datasets", timeout=500).json()
10
+
11
+ st.sidebar.title("Datasets")
12
+ ds = st.sidebar.selectbox(options=[ d["name"] for d in datasets],
13
+ label="Select your dataset")
14
+ print(ds)
15
+ if ds:
16
+ query = st.text_input("Enter your search query",
17
+ placeholder="Ask your question")
18
+ if query:
19
+ answer = requests.get(f"http://localhost:8080/v1/datasets/{ds}/answer?query={query}",
20
+ timeout=5000 )
21
+
22
+ print(answer.json()["answer"])
23
+ st.write(answer.json()["answer"])
24
+ else:
25
+ st.write("Choose your dataset!")
requirements.txt CHANGED
@@ -10,4 +10,4 @@ faiss-cpu
10
  qdrant-client
11
  elasticsearch
12
  sentence_transformers
13
-
 
10
  qdrant-client
11
  elasticsearch
12
  sentence_transformers
13
+ streamlit
run.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ python -m uvicorn "main:app" "--host" "0.0.0.0" "--port" "8080" &
3
+
4
+ #active wait- container won't quit
5
+ while ! timeout 1 bash -c "echo > /dev/tcp/localhost/8080"; do sleep 5; done
6
+
7
+ export be_url=`awk 'END{print "http://"$1":8080"}' /etc/hosts`
8
+ python -m streamlit run app.py