Spaces:
Runtime error
Runtime error
added code files
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import openai
|
3 |
+
import sys, getopt
|
4 |
+
from datetime import datetime
|
5 |
+
|
6 |
+
from main import chatgpt_prompt, get_chatgpt_resp, generate_kyc_output, gsearch
|
7 |
+
|
8 |
+
# Function to perform the search
|
9 |
+
# This is a placeholder function, replace it with your actual search implementation
|
10 |
+
def perform_search(pname, keywords, num_results):
|
11 |
+
# Google search for the person name and get the first 20 query links
|
12 |
+
search_links = gsearch(pname, num_results)
|
13 |
+
|
14 |
+
# Construct the prompt
|
15 |
+
prompt_text = chatgpt_prompt(pname, search_links)
|
16 |
+
#get ChatGPT response
|
17 |
+
resp = get_chatgpt_resp(prompt_text)
|
18 |
+
# Create PDF with links and summary
|
19 |
+
rep_txt= generate_kyc_output(pname, search_links, resp)
|
20 |
+
return (rep_txt)
|
21 |
+
|
22 |
+
# Streamlit app
|
23 |
+
st.title("Search App")
|
24 |
+
|
25 |
+
# Input fields
|
26 |
+
name = st.text_input("Enter your name:")
|
27 |
+
keywords = st.text_input("Enter search keywords:")
|
28 |
+
num_results = st.slider("Choose the number of search results:", 5, 30, 5, 5)
|
29 |
+
|
30 |
+
# Search button
|
31 |
+
if st.button("Search"):
|
32 |
+
# Perform the search and display the results
|
33 |
+
if name and keywords:
|
34 |
+
search_results = perform_search(name, keywords, num_results)
|
35 |
+
st.subheader(f"Search results for '{name}':")
|
36 |
+
st.write(search_results)
|
37 |
+
else:
|
38 |
+
st.error("Please enter your name and search keywords before searching.")
|
main.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import config
|
3 |
+
import openai
|
4 |
+
import sys, getopt
|
5 |
+
from datetime import datetime
|
6 |
+
|
7 |
+
def get_chatgpt_resp(question):
|
8 |
+
openai.api_key = config.OPENAI_API_KEY
|
9 |
+
response = openai.ChatCompletion.create(
|
10 |
+
model='gpt-3.5-turbo',
|
11 |
+
messages=[
|
12 |
+
{"role":"system","content":"You are a chatbot"},
|
13 |
+
{"role":"system","content":question}]
|
14 |
+
)
|
15 |
+
result = ''
|
16 |
+
for choice in response.choices:
|
17 |
+
result+=choice.message.content
|
18 |
+
|
19 |
+
return (result)
|
20 |
+
|
21 |
+
def gsearch(pname, num_results):
|
22 |
+
try:
|
23 |
+
from googlesearch import search
|
24 |
+
except ImportError:
|
25 |
+
print("No module named 'google' found")
|
26 |
+
|
27 |
+
# Google Search and return 10 links
|
28 |
+
query = pname
|
29 |
+
search_links = []
|
30 |
+
for j in search(query, tld="com", num=num_results, stop=num_results, pause=2):
|
31 |
+
search_links.append(j)
|
32 |
+
return(search_links)
|
33 |
+
|
34 |
+
|
35 |
+
def chatgpt_prompt(pname, search_links):
|
36 |
+
all_links = '\n'.join(map(str,search_links))
|
37 |
+
prompt_text = "You are a expert KYC analyst. I need help to identify if there is any adverse news about {}\
|
38 |
+
in the following links. \n {}. \n. In the reply include a 20 word summary of the text in each link and if you find any adverse\
|
39 |
+
news (Yes or No)".format(pname, all_links)
|
40 |
+
return(prompt_text)
|
41 |
+
|
42 |
+
def generate_kyc_output(pname, search_links, chat_response):
|
43 |
+
rep_txt = ''
|
44 |
+
|
45 |
+
rep_txt += 'Summary of Google Search for {} \n'.format(pname)
|
46 |
+
rep_txt += '\n'
|
47 |
+
rep_txt += "Report generated on {} \n".format(datetime.now())
|
48 |
+
#rep_txt += "----------------------------------------------------- \n"
|
49 |
+
rep_txt += '\n'
|
50 |
+
rep_txt += "Top Google Search Links "
|
51 |
+
rep_txt += '\n'
|
52 |
+
rep_txt += '\n'.join(map(str,search_links))
|
53 |
+
#rep_txt += "\n----------------------------------------------------- \n"
|
54 |
+
rep_txt += '\n'
|
55 |
+
rep_txt+= "\n Summary of searches and adverse news findings \n"
|
56 |
+
#rep_txt += "----------------------------------------------------- \n"
|
57 |
+
rep_txt += chat_response
|
58 |
+
|
59 |
+
return(rep_txt)
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
def main(argv):
|
65 |
+
try:
|
66 |
+
opts, args = getopt.getopt(argv,"i:", ["person="])
|
67 |
+
except getopt.GetoptError:
|
68 |
+
print ('Usage: python app.py --person=<person name>')
|
69 |
+
sys.exit(2)
|
70 |
+
for opt, arg in opts:
|
71 |
+
if opt == '--person':
|
72 |
+
pname = arg
|
73 |
+
# Google search for the person name and get the first 20 query links
|
74 |
+
search_links = gsearch(pname)
|
75 |
+
|
76 |
+
# Construct the prompt
|
77 |
+
prompt_text = chatgpt_prompt(pname, search_links)
|
78 |
+
|
79 |
+
#get ChatGPT response
|
80 |
+
resp = get_chatgpt_resp(prompt_text)
|
81 |
+
|
82 |
+
# Create PDF with links and summary
|
83 |
+
rep_txt= generate_kyc_output(pname, search_links, resp)
|
84 |
+
|
85 |
+
print(rep_txt)
|
86 |
+
|
87 |
+
|
88 |
+
if __name__ == "__main__":
|
89 |
+
main(sys.argv[1:])
|