Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
therapy/Healing[[:space:]]the[[:space:]]shame[[:space:]]that[[:space:]]binds[[:space:]]you[[:space:]]-[[:space:]]PDF[[:space:]]Room.pdf filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
therapy/Loch[[:space:]]Kelly[[:space:]]-[[:space:]]The[[:space:]]Way[[:space:]]of[[:space:]]Effortless[[:space:]]Mindfulness[[:space:]]A[[:space:]]Revolutionary[[:space:]]Guide[[:space:]]for[[:space:]]Living[[:space:]]an[[:space:]]Awakened[[:space:]]Life-Sounds[[:space:]]True[[:space:]](2018).pdf filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: pink
|
| 5 |
-
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.39.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: therapy0.1
|
| 3 |
+
app_file: kb.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 3.39.0
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
kb.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_index import SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage
|
| 2 |
+
from langchain.chat_models import ChatOpenAI
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import sys
|
| 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"] = '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'
|
| 16 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 17 |
+
|
| 18 |
+
# Define the rate limit for API calls (requests per second)
|
| 19 |
+
RATE_LIMIT = 3
|
| 20 |
+
|
| 21 |
+
# Implement the rate limiting decorator
|
| 22 |
+
@sleep_and_retry
|
| 23 |
+
@limits(calls=RATE_LIMIT, period=1)
|
| 24 |
+
def create_service_context():
|
| 25 |
+
|
| 26 |
+
#constraint parameters
|
| 27 |
+
max_input_size = 4096
|
| 28 |
+
num_outputs = 512
|
| 29 |
+
max_chunk_overlap = 20
|
| 30 |
+
chunk_size_limit = 600
|
| 31 |
+
|
| 32 |
+
#allows the user to explicitly set certain constraint parameters
|
| 33 |
+
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
| 34 |
+
|
| 35 |
+
#LLMPredictor is a wrapper class around LangChain's LLMChain that allows easy integration into LlamaIndex
|
| 36 |
+
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.5, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
|
| 37 |
+
|
| 38 |
+
#constructs service_context
|
| 39 |
+
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
|
| 40 |
+
return service_context
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# Implement the rate limiting decorator
|
| 44 |
+
@sleep_and_retry
|
| 45 |
+
@limits(calls=RATE_LIMIT, period=1)
|
| 46 |
+
def data_ingestion_indexing(directory_path):
|
| 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()
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
#persist index to disk, default "storage" folder
|
| 57 |
+
index.storage_context.persist()
|
| 58 |
+
|
| 59 |
+
return index
|
| 60 |
+
|
| 61 |
+
def data_querying(input_text):
|
| 62 |
+
|
| 63 |
+
#rebuild storage context
|
| 64 |
+
storage_context = StorageContext.from_defaults(persist_dir="./storage")
|
| 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,
|
| 75 |
+
inputs=gr.components.Textbox(lines=7, label="Enter your question"),
|
| 76 |
+
outputs="text",
|
| 77 |
+
title="Therapy GPT 0.1 pre alpha")
|
| 78 |
+
|
| 79 |
+
#passes in data directory
|
| 80 |
+
index = data_ingestion_indexing("therapy")
|
| 81 |
+
iface.launch(share=True)
|
therapy/Healing the shame that binds you - PDF Room.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2df9759eb1fe39e57d374747df151b46a495c5c354c95edad0f063dc8badad11
|
| 3 |
+
size 3399342
|
therapy/Loch Kelly - The Way of Effortless Mindfulness A Revolutionary Guide for Living an Awakened Life-Sounds True (2018).pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0da2de7ec8fa9cd9496854f2d7935939f91edd58198ce3f9b057485ac592c266
|
| 3 |
+
size 1862714
|