Spaces:
Runtime error
Runtime error
Zihao Wang
commited on
Commit
•
bffea63
1
Parent(s):
67194d1
add app
Browse files- app.py +31 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain.tools import Tool
|
3 |
+
from langchain_community.utilities import GoogleSearchAPIWrapper
|
4 |
+
import os
|
5 |
+
|
6 |
+
os.environ["GOOGLE_CSE_ID"] = "222a4a8ae035a4d1d"
|
7 |
+
os.environ["GOOGLE_API_KEY"] = "AIzaSyBxEUXINrQ313UZbgHEQXZSvTNADgOv9K0"
|
8 |
+
|
9 |
+
def get_search(query:str="", k:int=1):
|
10 |
+
search = GoogleSearchAPIWrapper(k=k)
|
11 |
+
def search_results(query):
|
12 |
+
return search.results(query, k)
|
13 |
+
tool = Tool(
|
14 |
+
name="Google Search Snippets",
|
15 |
+
description="Search Google for recent results.",
|
16 |
+
func=search_results,
|
17 |
+
)
|
18 |
+
ref_text = tool.run(query)
|
19 |
+
return ref_text
|
20 |
+
|
21 |
+
def search(query:str):
|
22 |
+
search_result = get_search(query,1)[0]
|
23 |
+
title = search_result['title']
|
24 |
+
link = search_result['link']
|
25 |
+
return_str = f"""title: {title}\nlink: {link}"""
|
26 |
+
return return_str
|
27 |
+
|
28 |
+
demo = gr.Interface(fn=search, inputs="textbox", outputs="textbox")
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
openai
|
3 |
+
langchain
|
4 |
+
tiktoken
|
5 |
+
html2text
|