azamat commited on
Commit
a20be5b
·
1 Parent(s): 72a12cd
Files changed (3) hide show
  1. app.py +11 -0
  2. requirements.txt +1 -0
  3. weaviate_explorer.py +21 -0
app.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from weaviate_explorer import WeaviateExplorer
3
+
4
+ weaviate_explorer = WeaviateExplorer()
5
+
6
+ def search(query):
7
+ shorts = weaviate_explorer.explore(query)
8
+ return "\n\n".join([f"{r['title']}\n{r['link']}" for r in shorts])
9
+
10
+ iface = gr.Interface(fn=search, inputs="text", outputs="text")
11
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ weaviate-client
weaviate_explorer.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import weaviate
3
+
4
+ class WeaviateExplorer:
5
+
6
+ def __init__(self):
7
+ self.client = weaviate.Client(
8
+ url = os.getenv("WEAVIATE_CLUSTER_URL"),
9
+ auth_client_secret=weaviate.auth.AuthApiKey(api_key=os.getenv("WEAVIATE_API_KEY"))
10
+ )
11
+
12
+ def explore(self, query):
13
+ response = (
14
+ self.client.query
15
+ .get("Short", ["title", "link"])
16
+ .with_near_text({"concepts": [query]})
17
+ .with_limit(5)
18
+ .do()
19
+ )
20
+
21
+ return response['data']['Get']['Short']