enoreyes tizze commited on
Commit
b5f78f9
0 Parent(s):

Duplicate from tizze/websitechatbot

Browse files

Co-authored-by: tt <[email protected]>

Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +71 -0
  4. github +1 -0
  5. requirements.txt +5 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Websitechatbot
3
+ emoji: 🏢
4
+ colorFrom: green
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.17.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: unknown
11
+ duplicated_from: tizze/websitechatbot
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ from langchain import OpenAI, ConversationChain
5
+ from langchain.prompts import PromptTemplate
6
+ from langchain.embeddings.openai import OpenAIEmbeddings
7
+ from langchain.text_splitter import CharacterTextSplitter
8
+ from langchain.vectorstores.faiss import FAISS
9
+ from langchain.docstore.document import Document
10
+ from langchain.agents import Tool
11
+ from langchain.chains.conversation.memory import ConversationBufferMemory
12
+ from langchain.utilities import GoogleSearchAPIWrapper
13
+ from langchain.agents import initialize_agent
14
+
15
+ from langchain.chains.conversation.memory import ConversationEntityMemory
16
+ from langchain.chains.conversation.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE
17
+
18
+ from langchain.agents import ZeroShotAgent, Tool, AgentExecutor
19
+ from langchain import SerpAPIWrapper, LLMChain
20
+
21
+ # ツールの準備
22
+ search = GoogleSearchAPIWrapper()
23
+ tools = [
24
+ Tool(
25
+ name = "Current Search",
26
+ func=search.run,
27
+ description="Use this allways",
28
+ ),
29
+ ]
30
+
31
+ # メモリの準備
32
+ memory = ConversationBufferMemory(memory_key="chat_history")
33
+
34
+ # エージェントの準備
35
+ llm=OpenAI(model_name = "text-davinci-003",temperature=0)
36
+ agent_chain = initialize_agent(
37
+ tools,
38
+ llm,
39
+ agent="zero-shot-react-description",
40
+ verbose=True,
41
+ memory=memory
42
+ )
43
+
44
+ def chat(message, site,history):
45
+ history = history or []
46
+ #siteの//以前を削除
47
+ site = site.replace("https://","")
48
+ response = ""
49
+ try:
50
+ response = agent_chain.run(input=message+" site:"+site)
51
+ except KeyError:
52
+ if not response:
53
+ response = "not found in the site"
54
+ history.append((message, response))
55
+
56
+ return history, history
57
+
58
+
59
+ with gr.Blocks() as demo:
60
+ gr.Markdown("<h3><center>WebSiteChatBotAI</center></h3>")
61
+ gr.Markdown("<p><center>paste web site URL and input question and push Run</center></p>")
62
+ site = gr.Textbox(placeholder="paste URL",label="WebSite")
63
+ chatbot = gr.Chatbot()
64
+ with gr.Row():
65
+ inp = gr.Textbox(placeholder="Question",label =None)
66
+ btn = gr.Button("Run").style(full_width=False)
67
+ state = gr.State()
68
+ agent_state = gr.State()
69
+ btn.click(chat, [inp,site,state],[chatbot, state])
70
+ if __name__ == '__main__':
71
+ demo.launch()
github ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit f9b4d012cf772c42a52ca4c1395fd75bbbbf5437
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ gradio
4
+ requests
5
+ google-api-python-client