henryhyunwookim commited on
Commit
e54820e
·
verified ·
1 Parent(s): 51c3cfe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import serpapi
2
+ import gradio as gr
3
+ from langchain_google_genai import ChatGoogleGenerativeAI
4
+
5
+ from utils.utils import summarize_search_result, get_prompt
6
+
7
+
8
+ def main(search_query, search_location, serp_api_key):
9
+ search_response = serpapi.search(
10
+ q=search_query,
11
+ location=search_location,
12
+ api_key=serp_api_key
13
+ ) # engine="google", location="Austin, Texas", hl="en", gl="us"
14
+
15
+ search_summary = summarize_search_result(search_response)
16
+
17
+ prompt = get_prompt(search_query, search_summary)
18
+
19
+ chat_model = ChatGoogleGenerativeAI(
20
+ model="gemini-pro",
21
+ convert_system_message_to_human=True,
22
+ temperature=0.0, # temperature=0.7 (default)
23
+ # top_p=0.5,
24
+ )
25
+ response = chat_model.invoke(prompt)
26
+
27
+ return response.content
28
+
29
+
30
+ if __name__ == "__main__":
31
+ try:
32
+ app = gr.Interface(
33
+ fn=main,
34
+ inputs=[
35
+ gr.Textbox(label="Search Query (検索クエリ)"),
36
+ gr.Textbox(label="Search Location (検索を行う国を英語で入力してください)"),
37
+ gr.Textbox(label="SERP API Key (https://serpapi.com/manage-api-key)")
38
+ ],
39
+ outputs=[gr.Textbox(label="Search Result (検索結果)")],
40
+ title="Google Search enhanced by LLM"
41
+ )
42
+ app.launch(share=True)
43
+ except Exception as e:
44
+ raise e