henryhyunwookim
commited on
Commit
β’
092eaa8
1
Parent(s):
297b623
Update app.py
Browse filesUpdate to get google api key and cse id from user input
app.py
CHANGED
@@ -1,25 +1,22 @@
|
|
|
|
1 |
from dotenv import load_dotenv
|
2 |
import gradio as gr
|
3 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
4 |
from langchain.agents import load_tools, initialize_agent
|
5 |
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
llm = ChatGoogleGenerativeAI(
|
12 |
-
model="gemini-pro",
|
13 |
-
temperature=0.0, # temperature=0.7 (default)
|
14 |
-
# top_p=0.5,
|
15 |
-
)
|
16 |
-
tools = load_tools(["google-search"], llm=llm)
|
17 |
-
|
18 |
-
|
19 |
-
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
def main(query):
|
23 |
return agent.run(query)
|
24 |
|
25 |
|
@@ -27,8 +24,11 @@ if __name__ == "__main__":
|
|
27 |
try:
|
28 |
app = gr.Interface(
|
29 |
fn=main,
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
outputs=[gr.Textbox(label="Search Result (ζ€η΄’η΅ζ)")],
|
33 |
title="Google Search enhanced by LLM"
|
34 |
)
|
|
|
1 |
+
import os
|
2 |
from dotenv import load_dotenv
|
3 |
import gradio as gr
|
4 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
5 |
from langchain.agents import load_tools, initialize_agent
|
6 |
|
7 |
|
8 |
+
def main(query, google_api_key, google_cse_id):
|
9 |
+
# Set environment variables
|
10 |
+
os.environ["GOOGLE_API_KEY"] = google_api_key
|
11 |
+
os.environ["GOOGLE_CSE_ID"] = google_cse_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
llm = ChatGoogleGenerativeAI(
|
14 |
+
model="gemini-pro",
|
15 |
+
temperature=0.0
|
16 |
+
)
|
17 |
+
tools = load_tools(["google-search"], llm=llm)
|
18 |
+
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
|
19 |
|
|
|
20 |
return agent.run(query)
|
21 |
|
22 |
|
|
|
24 |
try:
|
25 |
app = gr.Interface(
|
26 |
fn=main,
|
27 |
+
inputs=[
|
28 |
+
gr.Textbox(label="Search Query (ζ€η΄’γ―γ¨γͺ)"),
|
29 |
+
gr.Textbox(label="Google API Key (https://console.cloud.google.com/apis/credentials)"),
|
30 |
+
gr.Textbox(label="Google Programmable Search Engine (https://programmablesearchengine.google.com)")
|
31 |
+
],
|
32 |
outputs=[gr.Textbox(label="Search Result (ζ€η΄’η΅ζ)")],
|
33 |
title="Google Search enhanced by LLM"
|
34 |
)
|