Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitignore +2 -1
- front_end.py +35 -12
- rag.py +2 -3
.gitignore
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
.venv
|
2 |
.env
|
3 |
-
*pycache*
|
|
|
|
1 |
.venv
|
2 |
.env
|
3 |
+
*pycache*
|
4 |
+
voc_bot
|
front_end.py
CHANGED
@@ -3,22 +3,45 @@ from rag import mongo_rag_tool
|
|
3 |
from gradio.themes.base import Base
|
4 |
|
5 |
# Create an instance of GradIO
|
6 |
-
|
7 |
-
|
8 |
with gr.Blocks(theme=Base(), title="Market Research and VOC bot") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
gr.Markdown(
|
10 |
"""
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
with gr.Row():
|
15 |
-
button = gr.Button("Submit", variant="primary")
|
16 |
-
with gr.Column():
|
17 |
-
output1 = gr.Textbox(lines=1, max_lines=10, label="Answer:")
|
18 |
-
output2 = gr.Textbox(lines=1, max_lines=10, label="Sources:")
|
19 |
|
20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
button
|
|
|
23 |
|
24 |
-
demo.launch()
|
|
|
3 |
from gradio.themes.base import Base
|
4 |
|
5 |
# Create an instance of GradIO
|
|
|
|
|
6 |
with gr.Blocks(theme=Base(), title="Market Research and VOC bot") as demo:
|
7 |
+
# A styled header for the app
|
8 |
+
gr.Markdown(
|
9 |
+
"""
|
10 |
+
<div style='text-align: center; font-size: 24px; font-weight: bold; margin-bottom: 20px;'>
|
11 |
+
Chat with your data
|
12 |
+
</div>
|
13 |
+
"""
|
14 |
+
)
|
15 |
+
|
16 |
+
# Input fields for the collection and the question, with descriptive text
|
17 |
gr.Markdown(
|
18 |
"""
|
19 |
+
<div style='text-align: left; font-size: 18px; margin-bottom: 10px;'>
|
20 |
+
Enter the collection and your query to get relevant answers:
|
21 |
+
</div>
|
22 |
+
"""
|
23 |
+
)
|
24 |
+
collection_textbox = gr.Textbox(label="Enter your Collection:", placeholder="e.g., market_data", lines=1)
|
25 |
+
query_textbox = gr.Textbox(label="Enter your Question:", placeholder="Type your question here...", lines=1)
|
26 |
+
|
27 |
+
# Submit button with some spacing and central alignment
|
28 |
with gr.Row():
|
29 |
+
button = gr.Button("Submit", variant="primary", size="lg")
|
|
|
|
|
|
|
30 |
|
31 |
+
# Output section for displaying the answer and sources one below the other
|
32 |
+
gr.Markdown(
|
33 |
+
"""
|
34 |
+
<div style='text-align: left; font-size: 18px; margin-bottom: 10px;'>
|
35 |
+
Output:
|
36 |
+
</div>
|
37 |
+
"""
|
38 |
+
)
|
39 |
+
# Using a Column to place the answer and source outputs one after the other
|
40 |
+
with gr.Column():
|
41 |
+
answer_output = gr.Textbox(lines=5, label="Answer:", max_lines=50)
|
42 |
+
source_output = gr.Textbox(lines=5, label="Sources:", max_lines=50)
|
43 |
|
44 |
+
# Connect the button to the function
|
45 |
+
button.click(mongo_rag_tool, inputs=[query_textbox, collection_textbox], outputs=[answer_output, source_output])
|
46 |
|
47 |
+
demo.launch()
|
rag.py
CHANGED
@@ -13,19 +13,18 @@ load_dotenv()
|
|
13 |
INDEX_NAME = "vector_index"
|
14 |
DATABASE_NAME = "scraped_data_db"
|
15 |
|
16 |
-
def mongo_rag_tool(query: str) -> str:
|
17 |
"""
|
18 |
This function is used to retrieve documents from a MongoDB database and then use the RAG model to answer the query.
|
19 |
The documents that are most semantically close to the query are returned.
|
20 |
args:
|
21 |
query: str: The query that you want to use to retrieve documents
|
22 |
collection_name: str: The name of the collection in the MongoDB database
|
23 |
-
output_filename: str: The name of the output file where the results will be saved
|
24 |
returns:
|
25 |
str: The answer to the query
|
26 |
"""
|
27 |
try:
|
28 |
-
collection_name = os.getenv("MONGODB_COLLECTION_NAME")
|
29 |
# Connect to the MongoDB database
|
30 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
31 |
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key, disallowed_special=(), model="text-embedding-3-small")
|
|
|
13 |
INDEX_NAME = "vector_index"
|
14 |
DATABASE_NAME = "scraped_data_db"
|
15 |
|
16 |
+
def mongo_rag_tool(query: str, collection_name: str) -> str:
|
17 |
"""
|
18 |
This function is used to retrieve documents from a MongoDB database and then use the RAG model to answer the query.
|
19 |
The documents that are most semantically close to the query are returned.
|
20 |
args:
|
21 |
query: str: The query that you want to use to retrieve documents
|
22 |
collection_name: str: The name of the collection in the MongoDB database
|
|
|
23 |
returns:
|
24 |
str: The answer to the query
|
25 |
"""
|
26 |
try:
|
27 |
+
#collection_name = os.getenv("MONGODB_COLLECTION_NAME")
|
28 |
# Connect to the MongoDB database
|
29 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
30 |
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key, disallowed_special=(), model="text-embedding-3-small")
|