SlothioAI commited on
Commit
000471a
·
0 Parent(s):

Duplicate from SlothioAI/CheckYourFacts

Browse files
Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +42 -0
  4. requirements.txt +7 -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,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: CheckYourFacts
3
+ emoji: 📈
4
+ colorFrom: purple
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 3.27.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: SlothioAI/CheckYourFacts
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from langchain.agents import Tool, load_tools, initialize_agent
3
+ from langchain.memory import ConversationBufferMemory
4
+ from langchain.chat_models import ChatOpenAI
5
+ from langchain.utilities import GoogleSearchAPIWrapper
6
+ from langchain.agents import initialize_agent
7
+ from langchain.utilities import WikipediaAPIWrapper
8
+ from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper
9
+ import gradio as gr
10
+
11
+ description = """
12
+ 👍 If you liked the app, sign up for my AI newsletter where I'll be sharing prompts, news, and tools like this one: [https://slothio.com/ai-newsletter/](https://slothio.com/ai-newsletter/)
13
+ """
14
+
15
+ def initialize_keys(openai_api_key, google_api_key, google_cse_id, wolfram_alpha_appid):
16
+ os.environ['OPENAI_API_KEY'] = openai_api_key
17
+ os.environ['GOOGLE_API_KEY'] = google_api_key
18
+ os.environ['GOOGLE_CSE_ID'] = google_cse_id
19
+ os.environ['WOLFRAM_ALPHA_APPID'] = wolfram_alpha_appid
20
+
21
+ def chat_response(input_text, openai_api_key, google_api_key, google_cse_id, wolfram_alpha_appid):
22
+ initialize_keys(openai_api_key, google_api_key, google_cse_id, wolfram_alpha_appid)
23
+
24
+ llm=ChatOpenAI(temperature=1)
25
+ search = GoogleSearchAPIWrapper()
26
+ tools = load_tools(["google-search", "wolfram-alpha", "wikipedia"], llm=llm)
27
+ memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
28
+
29
+ agent_chain = initialize_agent(tools, llm, agent="zero-shot-react-description",
30
+ verbose=True, memory=memory)
31
+ response = agent_chain.run(input=input_text)
32
+ return response
33
+
34
+ input_text = gr.inputs.Textbox(lines=2, label='Input Text')
35
+ openai_api_key = gr.inputs.Textbox(lines=1, label='OpenAI API Key', type='password')
36
+ google_api_key = gr.inputs.Textbox(lines=1, label='Google API Key', type='password')
37
+ google_cse_id = gr.inputs.Textbox(lines=1, label='Google CSE ID', type='password')
38
+ wolfram_alpha_appid = gr.inputs.Textbox(lines=1, label='Wolfram Alpha AppID', type='password')
39
+
40
+ interface = gr.Interface(fn=chat_response, inputs=[input_text, openai_api_key, google_api_key, google_cse_id, wolfram_alpha_appid], outputs="text", description=description)
41
+
42
+ interface.launch(share=False)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ openai==0.27.4
2
+ gradio==3.27.0
3
+ google-search-results==2.4.2
4
+ google-api-python-client==2.86.0
5
+ wolframalpha
6
+ langchain==0.0.148
7
+ wikipedia==1.4.0