Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- .idea/workspace.xml +28 -6
- __pycache__/constants.cpython-311.pyc +0 -0
- main.py +24 -33
- requirements.txt +4 -22
- venv/lib/python3.11/site-packages/gradio/launches.json +1 -1
.idea/workspace.xml
CHANGED
|
@@ -4,10 +4,7 @@
|
|
| 4 |
<option name="autoReloadType" value="SELECTIVE" />
|
| 5 |
</component>
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
-
<list default="true" id="389d532e-4eaf-4367-8bd6-095ab4d8b955" name="Changes" comment=""
|
| 8 |
-
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
| 9 |
-
<change beforePath="$PROJECT_DIR$/chat_engine.py" beforeDir="false" afterPath="$PROJECT_DIR$/chat_engine.py" afterDir="false" />
|
| 10 |
-
</list>
|
| 11 |
<option name="SHOW_DIALOG" value="false" />
|
| 12 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
| 13 |
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
@@ -23,6 +20,31 @@
|
|
| 23 |
<component name="Git.Settings">
|
| 24 |
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
| 25 |
</component>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
<component name="MarkdownSettingsMigration">
|
| 27 |
<option name="stateVersion" value="1" />
|
| 28 |
</component>
|
|
@@ -40,7 +62,7 @@
|
|
| 40 |
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
| 41 |
"RunOnceActivity.ShowReadmeOnStart": "true",
|
| 42 |
"WebServerToolWindowFactoryState": "false",
|
| 43 |
-
"git-widget-placeholder": "
|
| 44 |
"last_opened_file_path": "/home/draco/PycharmProjects/customChatBotDemo",
|
| 45 |
"node.js.detected.package.eslint": "true",
|
| 46 |
"node.js.detected.package.tslint": "true",
|
|
@@ -90,7 +112,7 @@
|
|
| 90 |
<workItem from="1693344352959" duration="1601000" />
|
| 91 |
<workItem from="1693345962391" duration="4297000" />
|
| 92 |
<workItem from="1693351210434" duration="1643000" />
|
| 93 |
-
<workItem from="1693353619587" duration="
|
| 94 |
</task>
|
| 95 |
<servers />
|
| 96 |
</component>
|
|
|
|
| 4 |
<option name="autoReloadType" value="SELECTIVE" />
|
| 5 |
</component>
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
+
<list default="true" id="389d532e-4eaf-4367-8bd6-095ab4d8b955" name="Changes" comment="" />
|
|
|
|
|
|
|
|
|
|
| 8 |
<option name="SHOW_DIALOG" value="false" />
|
| 9 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
| 10 |
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
|
|
| 20 |
<component name="Git.Settings">
|
| 21 |
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
| 22 |
</component>
|
| 23 |
+
<component name="GitToolBoxStore">
|
| 24 |
+
<option name="recentBranches">
|
| 25 |
+
<RecentBranches>
|
| 26 |
+
<option name="branchesForRepo">
|
| 27 |
+
<list>
|
| 28 |
+
<RecentBranchesForRepo>
|
| 29 |
+
<option name="branches">
|
| 30 |
+
<list>
|
| 31 |
+
<RecentBranch>
|
| 32 |
+
<option name="branchName" value="chat-engine" />
|
| 33 |
+
<option name="lastUsedInstant" value="1693355057" />
|
| 34 |
+
</RecentBranch>
|
| 35 |
+
<RecentBranch>
|
| 36 |
+
<option name="branchName" value="master" />
|
| 37 |
+
<option name="lastUsedInstant" value="1693355056" />
|
| 38 |
+
</RecentBranch>
|
| 39 |
+
</list>
|
| 40 |
+
</option>
|
| 41 |
+
<option name="repositoryRootUrl" value="file://$PROJECT_DIR$" />
|
| 42 |
+
</RecentBranchesForRepo>
|
| 43 |
+
</list>
|
| 44 |
+
</option>
|
| 45 |
+
</RecentBranches>
|
| 46 |
+
</option>
|
| 47 |
+
</component>
|
| 48 |
<component name="MarkdownSettingsMigration">
|
| 49 |
<option name="stateVersion" value="1" />
|
| 50 |
</component>
|
|
|
|
| 62 |
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
| 63 |
"RunOnceActivity.ShowReadmeOnStart": "true",
|
| 64 |
"WebServerToolWindowFactoryState": "false",
|
| 65 |
+
"git-widget-placeholder": "chat-engine",
|
| 66 |
"last_opened_file_path": "/home/draco/PycharmProjects/customChatBotDemo",
|
| 67 |
"node.js.detected.package.eslint": "true",
|
| 68 |
"node.js.detected.package.tslint": "true",
|
|
|
|
| 112 |
<workItem from="1693344352959" duration="1601000" />
|
| 113 |
<workItem from="1693345962391" duration="4297000" />
|
| 114 |
<workItem from="1693351210434" duration="1643000" />
|
| 115 |
+
<workItem from="1693353619587" duration="1897000" />
|
| 116 |
</task>
|
| 117 |
<servers />
|
| 118 |
</component>
|
__pycache__/constants.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/constants.cpython-311.pyc and b/__pycache__/constants.cpython-311.pyc differ
|
|
|
main.py
CHANGED
|
@@ -1,46 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
import openai
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
from
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
load_dotenv()
|
| 15 |
-
os.getenv("OPENAI_API_KEY")
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
vectorstore = Chroma(persist_directory="persist", embedding_function=OpenAIEmbeddings())
|
| 22 |
-
index = VectorStoreIndexWrapper(vectorstore=vectorstore)
|
| 23 |
-
index.load("persist")
|
| 24 |
-
else:
|
| 25 |
-
loader = DirectoryLoader("data/")
|
| 26 |
-
if PERSIST:
|
| 27 |
-
index = VectorstoreIndexCreator(vectorstore_kwargs={"persist_directory": "persist"}).from_loaders([loader])
|
| 28 |
-
else:
|
| 29 |
-
index = VectorstoreIndexCreator().from_loaders([loader])
|
| 30 |
|
| 31 |
-
|
| 32 |
-
model_name = "gpt-4" if use_gpt_4 else "gpt-3.5-turbo-16k"
|
| 33 |
-
chain = ConversationalRetrievalChain.from_llm(llm=ChatOpenAI(model=model_name),
|
| 34 |
-
retriever=index.vectorstore.as_retriever(search_kwargs={"k": 1}))
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
def answer_question(question):
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
iface = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
+
from llama_index import (
|
| 4 |
+
ServiceContext,
|
| 5 |
+
VectorStoreIndex,
|
| 6 |
+
SimpleDirectoryReader,
|
| 7 |
+
set_global_service_context,
|
| 8 |
+
)
|
| 9 |
+
from llama_index.llms import OpenAI
|
| 10 |
+
import openai
|
| 11 |
+
import constants
|
| 12 |
|
| 13 |
load_dotenv()
|
| 14 |
+
# openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 15 |
+
openai.api_key = constants.APIKEY
|
| 16 |
|
| 17 |
+
service_context = ServiceContext.from_defaults(
|
| 18 |
+
llm=OpenAI(model="gpt-3.5-turbo-16k", temperature=0)
|
| 19 |
+
)
|
| 20 |
+
set_global_service_context(service_context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
data = SimpleDirectoryReader(input_dir="./data/").load_data()
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
index = VectorStoreIndex.from_documents(data)
|
| 25 |
+
chat_engine = index.as_chat_engine(chat_mode="context")
|
| 26 |
|
| 27 |
|
| 28 |
def answer_question(question):
|
| 29 |
+
response = chat_engine.stream_chat(question)
|
| 30 |
+
response_text = ""
|
| 31 |
+
for token in response.response_gen:
|
| 32 |
+
print(token, end="")
|
| 33 |
+
response_text += token
|
| 34 |
+
return response_text
|
| 35 |
|
| 36 |
|
| 37 |
iface = gr.Interface(
|
requirements.txt
CHANGED
|
@@ -1,22 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
openai
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
pypdf==3.15.4
|
| 6 |
-
streamlit==1.26.0
|
| 7 |
-
streamlit-chat==0.1.1
|
| 8 |
-
tiktoken==0.4.0
|
| 9 |
-
youtube-transcript-api==0.6.1
|
| 10 |
-
faiss-cpu
|
| 11 |
-
gradio
|
| 12 |
-
unstructured
|
| 13 |
-
chromadb
|
| 14 |
-
llama-index==0.8.2
|
| 15 |
-
transformers
|
| 16 |
-
span-marker
|
| 17 |
-
nltk
|
| 18 |
-
llama-hub
|
| 19 |
-
tesseract
|
| 20 |
-
pytesseract
|
| 21 |
-
python-dotenv
|
| 22 |
-
PyCryptodome
|
|
|
|
| 1 |
+
gradio~=3.41.2
|
| 2 |
+
openai~=0.27.9
|
| 3 |
+
python-dotenv~=1.0.0
|
| 4 |
+
llama-index==0.8.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
venv/lib/python3.11/site-packages/gradio/launches.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"launches":
|
|
|
|
| 1 |
+
{"launches": 25}
|