henryhyunwookim's picture
Update app.py
f06e15d verified
raw
history blame
953 Bytes
from dotenv import load_dotenv
import gradio as gr
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.agents import load_tools, initialize_agent
# Load environment variables
_ = load_dotenv()
llm = ChatGoogleGenerativeAI(
model="gemini-pro",
temperature=0.0, # temperature=0.7 (default)
# top_p=0.5,
)
tools = load_tools(["google-search"], llm=llm)
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
def main(query):
return agent.run(query)
if __name__ == "__main__":
try:
app = gr.Interface(
fn=main,
# inputs=["text", "text"],
inputs=[gr.Textbox(label="Search Query (クエγƒͺγ‚’ε…₯εŠ›γ—γ¦γγ γ•γ„)")],
outputs=[gr.Textbox(label="Search Result (怜紒硐果)")],
title="Google Search enhanced by LLM"
)
app.launch(share=True)
except Exception as e:
raise e