alx-d commited on
Commit
e563f0c
·
1 Parent(s): f27775d

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,8 @@ 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
+ therapy2/Emotional[[:space:]]Schema[[:space:]]Therapy[[:space:]]-[[:space:]]Leahy.pdf filter=lfs diff=lfs merge=lfs -text
37
+ therapy2/Healing[[:space:]]developmental[[:space:]]trauma[[:space:]][[:space:]]how[[:space:]]early[[:space:]]trauma[[:space:]]affects[[:space:]]self-regulation,[[:space:]]self-image,[[:space:]]and[[:space:]]the[[:space:]]capacity[[:space:]]for[[:space:]]relationship[[:space:]]by[[:space:]]Laurence[[:space:]]Heller.pdf filter=lfs diff=lfs merge=lfs -text
38
+ therapy2/Jeffrey[[:space:]]Young[[:space:]]-[[:space:]]Reinventing[[:space:]]Your[[:space:]]Life_[[:space:]]The[[:space:]]Breakthough[[:space:]]Program[[:space:]]to[[:space:]]End[[:space:]]Negative[[:space:]]Behavior...[[:space:]]and[[:space:]]Feel[[:space:]]Great[[:space:]]Again[[:space:]]([[:space:]]PDFDrive[[:space:]]).pdf filter=lfs diff=lfs merge=lfs -text
39
+ therapy2/Korb[[:space:]]-[[:space:]]Upward[[:space:]]Sprial.pdf filter=lfs diff=lfs merge=lfs -text
40
+ therapy2/Set[[:space:]]Boundaries,[[:space:]]Find[[:space:]]Peace[[:space:]]A[[:space:]]guide[[:space:]]to[[:space:]]reclaiming[[:space:]]yourself[[:space:]]by[[:space:]]Nedra[[:space:]]Glover[[:space:]]Tawwab[[:space:]](z-lib.org).epub.pdf filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Therapy0.2
3
- emoji: 🏆
4
- colorFrom: indigo
5
- colorTo: blue
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.2
3
+ app_file: kb2.py
 
 
4
  sdk: gradio
5
  sdk_version: 3.39.0
 
 
6
  ---
 
 
kb2.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.2 pre alpha")
78
+
79
+ #passes in data directory
80
+ index = data_ingestion_indexing("therapy2")
81
+ iface.launch(inline=True)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ langchain==0.0.188
2
+ openai
3
+ llama_index==0.6.12
4
+ pypdf
5
+ PyCryptodome
6
+ ratelimit
therapy2/Emotional Schema Therapy - Leahy.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b0b59fd7076120c8cc92db92ab8261db049bcfd0e3f3e372d6fedcf3c031944a
3
+ size 4515681
therapy2/Healing developmental trauma how early trauma affects self-regulation, self-image, and the capacity for relationship by Laurence Heller.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3237a1780e1307797c3ef9ee1183fe086cc7eca97f580c07fa520ca4a31748d
3
+ size 2561178
therapy2/Jeffrey Young - Reinventing Your Life_ The Breakthough Program to End Negative Behavior... and Feel Great Again ( PDFDrive ).pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6768531c9db49da4258fb0061d93f16ddec3c5922f3f34473f33aad0d96205d9
3
+ size 38720346
therapy2/Korb - Upward Sprial.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e618b4a76186530de68b6aff472d1886eb9577ed651a8b0e998295df6e594a1
3
+ size 6409504
therapy2/Set Boundaries, Find Peace A guide to reclaiming yourself by Nedra Glover Tawwab (z-lib.org).epub.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a05cf926b1c7195d615a2a59a748ce500bbf6a132e1b38b60eb4038d0528ce5b
3
+ size 1734443