mijgis commited on
Commit
6c440de
1 Parent(s): 054e39d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -9,7 +9,6 @@ import json
9
  import uuid
10
  import tiktoken
11
  from openai import OpenAI
12
- #from dotenv import load_dotenv
13
  from langchain.text_splitter import RecursiveCharacterTextSplitter
14
  from langchain_core.documents import Document
15
  from langchain_community.document_loaders import PyPDFDirectoryLoader
@@ -17,16 +16,11 @@ from langchain_community.embeddings.sentence_transformer import (
17
  SentenceTransformerEmbeddings
18
  )
19
  from langchain_community.vectorstores import Chroma
20
-
21
  from langchain_community.chat_models import ChatOpenAI
22
-
23
  from huggingface_hub import CommitScheduler
24
  from pathlib import Path
25
 
26
-
27
-
28
  # Create Client
29
- #anyscale_api_key = 'esecret_gseacat1ltrafee81njti6867e'
30
  anyscale_api_key = os.getenv('anyscale_apiKey')
31
 
32
  client = OpenAI(base_url="https://api.endpoints.anyscale.com/v1",
@@ -34,8 +28,6 @@ client = OpenAI(base_url="https://api.endpoints.anyscale.com/v1",
34
  )
35
 
36
  # Define the embedding model and the vectorstore
37
- #model_name = "thenlper/gte-large"
38
- #embedding_model = "thenlper/gte-large"
39
  model_name = "mlabonne/NeuralHermes-2.5-Mistral-7B"
40
  embedding_model = SentenceTransformerEmbeddings(model_name="thenlper/gte-large")
41
 
@@ -49,9 +41,8 @@ vectorstore_persisted = Chroma(
49
  persist_directory=persisted_vectordb_location,
50
  embedding_function=embedding_model
51
  )
52
- test = str(vectorstore_persisted.get())[:20]
53
- # Prepare the logging functionality
54
 
 
55
  log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
56
  log_folder = log_file.parent
57
 
@@ -143,8 +134,7 @@ def predict(user_input,company):
143
  )
144
 
145
  prediction = response.choices[0].message.content.strip()
146
- #prediction = "CONTEXT LIST: " + str(context_list) + "CONTEXT FOR QUERY:" + str(context_for_query)
147
- #prediction = test + ' length of chunks (should equal 5) ' + str(len(relevant_document_chunks))
148
  except Exception as e:
149
  prediction = f'Sorry, I encountered the following error: \n {e}'
150
 
@@ -175,11 +165,8 @@ def predict(user_input,company):
175
  # The submit button is used to run the predict function
176
 
177
 
178
- textbox = gr.Textbox()
179
- company = gr.Radio(choices=['aws', 'google', 'Meta', 'msft', 'IBM'], label="Select a company:")
180
-
181
- #predict = gr.Button("Submit")
182
- #predict.click(predict, inputs=[textbox,company], outputs=[predict])
183
 
184
 
185
  model_output = gr.Label(label='Answer to your qestion')
 
9
  import uuid
10
  import tiktoken
11
  from openai import OpenAI
 
12
  from langchain.text_splitter import RecursiveCharacterTextSplitter
13
  from langchain_core.documents import Document
14
  from langchain_community.document_loaders import PyPDFDirectoryLoader
 
16
  SentenceTransformerEmbeddings
17
  )
18
  from langchain_community.vectorstores import Chroma
 
19
  from langchain_community.chat_models import ChatOpenAI
 
20
  from huggingface_hub import CommitScheduler
21
  from pathlib import Path
22
 
 
 
23
  # Create Client
 
24
  anyscale_api_key = os.getenv('anyscale_apiKey')
25
 
26
  client = OpenAI(base_url="https://api.endpoints.anyscale.com/v1",
 
28
  )
29
 
30
  # Define the embedding model and the vectorstore
 
 
31
  model_name = "mlabonne/NeuralHermes-2.5-Mistral-7B"
32
  embedding_model = SentenceTransformerEmbeddings(model_name="thenlper/gte-large")
33
 
 
41
  persist_directory=persisted_vectordb_location,
42
  embedding_function=embedding_model
43
  )
 
 
44
 
45
+ # Prepare the logging functionality
46
  log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
47
  log_folder = log_file.parent
48
 
 
134
  )
135
 
136
  prediction = response.choices[0].message.content.strip()
137
+
 
138
  except Exception as e:
139
  prediction = f'Sorry, I encountered the following error: \n {e}'
140
 
 
165
  # The submit button is used to run the predict function
166
 
167
 
168
+ textbox = gr.Textbox(label="Enter your question:")
169
+ company = gr.Radio(choices=['aws', 'google', 'Meta', 'msft', 'IBM'], label="Select a company:")
 
 
 
170
 
171
 
172
  model_output = gr.Label(label='Answer to your qestion')