henryhyunwookim's picture
Update app.py
dc8f606 verified
raw
history blame
1.4 kB
import os
import serpapi
import gradio as gr
from langchain_google_genai import ChatGoogleGenerativeAI
from utils.utils import summarize_search_result, get_prompt
def main(search_query, search_location, serp_api_key):
search_response = serpapi.search(
q=search_query,
location=search_location,
api_key=serp_api_key
) # engine="google", location="Austin, Texas", hl="en", gl="us"
search_summary = summarize_search_result(search_response)
prompt = get_prompt(search_query, search_summary)
chat_model = ChatGoogleGenerativeAI(
model="gemini-pro",
convert_system_message_to_human=True,
temperature=0.0, # temperature=0.7 (default)
# top_p=0.5,
)
response = chat_model.invoke(prompt)
return response.content
if __name__ == "__main__":
try:
app = gr.Interface(
fn=main,
inputs=[
gr.Textbox(label="Search Query (検索クエリ)"),
gr.Textbox(label="Search Location (検索を行う国を英語で入力してください)"),
gr.Textbox(label="SERP API Key (https://serpapi.com/manage-api-key)")
],
outputs=[gr.Textbox(label="Search Result (検索結果)")],
title="Google Search enhanced by LLM"
)
app.launch(share=True)
except Exception as e:
raise e