bstraehle commited on
Commit
838b33c
·
verified ·
1 Parent(s): dae5fc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -34
app.py CHANGED
@@ -4,7 +4,7 @@ import logging, os, sys, threading
4
 
5
  from datasets import load_dataset
6
  #from dotenv import load_dotenv, find_dotenv
7
- from custom_utils import connect_to_database, handle_user_prompt
8
 
9
  #from pydantic import BaseModel
10
  #from typing import Optional
@@ -33,39 +33,10 @@ def invoke(openai_api_key, prompt, rag_option):
33
  raise gr.Error("Retrieval-Augmented Generation is required.")
34
 
35
  with lock:
36
- prompt = """
37
- I want to stay in a place that's warm and friendly,
38
- and not too far from resturants, can you recommend a place?
39
- Include a reason as to why you've chosen your selection.
40
- """
41
-
42
- """
43
- print("111")
44
- dataset = load_dataset("MongoDB/airbnb_embeddings", streaming=True, split="train")
45
- #dataset = dataset.take(100)
46
- print("222")
47
- # Convert the dataset to a pandas dataframe
48
- dataset_df = pd.DataFrame(dataset)
49
- #dataset_df.head(5)
50
- #print("Columns:", dataset_df.columns)
51
-
52
- listings = process_records(dataset_df)
53
- print("333")
54
- """
55
-
56
- print("444")
57
  db, collection = connect_to_database()
58
-
59
- """
60
- collection.delete_many({})
61
- collection.insert_many(listings)
62
- print("Data ingestion into MongoDB completed")
63
- print("555")
64
-
65
- print("666")
66
- # Not available in free tier
67
- #setup_vector_search_index(collection=collection)
68
- """
69
 
70
  """
71
  print("777")
@@ -90,10 +61,12 @@ def invoke(openai_api_key, prompt, rag_option):
90
 
91
  gr.close_all()
92
 
 
 
93
  demo = gr.Interface(
94
  fn = invoke,
95
  inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
96
- gr.Textbox(label = "Prompt", value = "TODO", lines = 1),
97
  gr.Radio([RAG_OFF, RAG_NAIVE, RAG_ADVANCED], label = "Retrieval-Augmented Generation", value = RAG_ADVANCED)],
98
  outputs = [gr.Markdown(label = "Completion")],
99
  title = "Context-Aware Reasoning Application",
 
4
 
5
  from datasets import load_dataset
6
  #from dotenv import load_dotenv, find_dotenv
7
+ from custom_utils import connect_to_database, rag_ingestion, handle_user_prompt
8
 
9
  #from pydantic import BaseModel
10
  #from typing import Optional
 
33
  raise gr.Error("Retrieval-Augmented Generation is required.")
34
 
35
  with lock:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  db, collection = connect_to_database()
37
+
38
+ if (RAG_INGESTION):
39
+ rag_ingestion(collection)
 
 
 
 
 
 
 
 
40
 
41
  """
42
  print("777")
 
61
 
62
  gr.close_all()
63
 
64
+ PROMPT = "I want to stay in a place that's warm and friendly, and not too far from restaurants."
65
+
66
  demo = gr.Interface(
67
  fn = invoke,
68
  inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
69
+ gr.Textbox(label = "Prompt", value = PROMPT, lines = 1),
70
  gr.Radio([RAG_OFF, RAG_NAIVE, RAG_ADVANCED], label = "Retrieval-Augmented Generation", value = RAG_ADVANCED)],
71
  outputs = [gr.Markdown(label = "Completion")],
72
  title = "Context-Aware Reasoning Application",