Upload folder using huggingface_hub
Browse files- longevity.py +6 -7
longevity.py
CHANGED
|
@@ -5,15 +5,14 @@ import sys
|
|
| 5 |
import os
|
| 6 |
import openai
|
| 7 |
from ratelimit import limits, sleep_and_retry
|
| 8 |
-
import streamlit
|
| 9 |
|
| 10 |
# fixing bugs
|
| 11 |
-
# 1. open ai key: https://stackoverflow.com/questions/76425556/tenacity-retryerror-retryerrorfuture-at-0x7f89bc35eb90-state-finished-raised
|
| 12 |
# 2. rate limit error in lang_chain default version - install langchain==0.0.188. https://github.com/jerryjliu/llama_index/issues/924
|
| 13 |
-
# 3. added true Config variable in langchain: https://github.com/pydantic/pydantic/issues/3320
|
| 14 |
|
| 15 |
|
| 16 |
-
os.environ["OPENAI_API_KEY"] =
|
| 17 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 18 |
|
| 19 |
# Define the rate limit for API calls (requests per second)
|
|
@@ -48,7 +47,7 @@ def data_ingestion_indexing(directory_path):
|
|
| 48 |
|
| 49 |
#loads data from the specified directory path
|
| 50 |
documents = SimpleDirectoryReader(directory_path).load_data()
|
| 51 |
-
|
| 52 |
#when first building the index
|
| 53 |
index = GPTVectorStoreIndex.from_documents(
|
| 54 |
documents, service_context=create_service_context()
|
|
@@ -66,10 +65,10 @@ def data_querying(input_text):
|
|
| 66 |
|
| 67 |
#loads index from storage
|
| 68 |
index = load_index_from_storage(storage_context, service_context=create_service_context())
|
| 69 |
-
|
| 70 |
#queries the index with the input text
|
| 71 |
response = index.as_query_engine().query(input_text)
|
| 72 |
-
|
| 73 |
return response.response
|
| 74 |
|
| 75 |
iface = gr.Interface(fn=data_querying,
|
|
|
|
| 5 |
import os
|
| 6 |
import openai
|
| 7 |
from ratelimit import limits, sleep_and_retry
|
|
|
|
| 8 |
|
| 9 |
# fixing bugs
|
| 10 |
+
# 1. open ai key: https://stackoverflow.com/questions/76425556/tenacity-retryerror-retryerrorfuture-at-0x7f89bc35eb90-state-finished-raised
|
| 11 |
# 2. rate limit error in lang_chain default version - install langchain==0.0.188. https://github.com/jerryjliu/llama_index/issues/924
|
| 12 |
+
# 3. added true Config variable in langchain: https://github.com/pydantic/pydantic/issues/3320
|
| 13 |
|
| 14 |
|
| 15 |
+
os.environ["OPENAI_API_KEY"] = os.environ.get("openai_key")
|
| 16 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 17 |
|
| 18 |
# Define the rate limit for API calls (requests per second)
|
|
|
|
| 47 |
|
| 48 |
#loads data from the specified directory path
|
| 49 |
documents = SimpleDirectoryReader(directory_path).load_data()
|
| 50 |
+
|
| 51 |
#when first building the index
|
| 52 |
index = GPTVectorStoreIndex.from_documents(
|
| 53 |
documents, service_context=create_service_context()
|
|
|
|
| 65 |
|
| 66 |
#loads index from storage
|
| 67 |
index = load_index_from_storage(storage_context, service_context=create_service_context())
|
| 68 |
+
|
| 69 |
#queries the index with the input text
|
| 70 |
response = index.as_query_engine().query(input_text)
|
| 71 |
+
|
| 72 |
return response.response
|
| 73 |
|
| 74 |
iface = gr.Interface(fn=data_querying,
|