|
from dotenv import load_dotenv |
|
import gradio as gr |
|
from langchain_google_genai import ChatGoogleGenerativeAI |
|
from langchain.agents import load_tools, initialize_agent |
|
|
|
|
|
|
|
_ = load_dotenv() |
|
|
|
|
|
llm = ChatGoogleGenerativeAI( |
|
model="gemini-pro", |
|
temperature=0.0, |
|
|
|
) |
|
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=[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 |