bkoz commited on
Commit
21f1e47
1 Parent(s): a1f36e8

initial code

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -8,15 +8,11 @@ import os
8
  import requests
9
  import json
10
 
11
- """
12
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
13
- """
14
-
15
  logging.basicConfig(level=logging.INFO)
16
 
17
  client = weaviate.connect_to_embedded(
18
  headers={
19
- "X-Huggingface-Api-Key": os.environ["HUGGINGFACE_API_KEY"] # Replace with your inference API key
20
  }
21
  )
22
 
@@ -36,7 +32,7 @@ questions = client.collections.create(
36
  generative_config=wvc.config.Configure.Generative.openai()
37
  )
38
  resp = requests.get('https://raw.githubusercontent.com/databyjp/wv_demo_uploader/main/weaviate_datasets/data/jeopardy_1k.json')
39
- data = json.loads(resp.text) # Load data
40
 
41
  question_objs = list()
42
  for i, d in enumerate(data):
@@ -49,20 +45,16 @@ for i, d in enumerate(data):
49
  "value": d["Value"]
50
  })
51
 
52
- logging.info('Importing Questions')
53
  questions = client.collections.get("Question")
54
  questions.data.insert_many(question_objs)
55
  logging.info('Finished Importing Questions')
56
 
57
  def respond(query):
58
 
59
- r = ""
60
- if client.is_ready():
61
- r = f'Found {len(client.cluster.nodes())} Weaviate nodes.'
62
-
63
  response = questions.query.near_text(
64
  query=query,
65
- limit=2
66
  )
67
 
68
  return response.objects[0].properties
@@ -70,7 +62,7 @@ def respond(query):
70
  demo = gr.Interface(fn=respond,
71
  inputs=gr.Textbox(
72
  label="Search the Jeopardy Vector Database",
73
- info="Query:",
74
  lines=1,
75
  value="Guitar",
76
  ),
 
8
  import requests
9
  import json
10
 
 
 
 
 
11
  logging.basicConfig(level=logging.INFO)
12
 
13
  client = weaviate.connect_to_embedded(
14
  headers={
15
+ "X-Huggingface-Api-Key": os.environ["HUGGINGFACE_API_KEY"]
16
  }
17
  )
18
 
 
32
  generative_config=wvc.config.Configure.Generative.openai()
33
  )
34
  resp = requests.get('https://raw.githubusercontent.com/databyjp/wv_demo_uploader/main/weaviate_datasets/data/jeopardy_1k.json')
35
+ data = json.loads(resp.text)
36
 
37
  question_objs = list()
38
  for i, d in enumerate(data):
 
45
  "value": d["Value"]
46
  })
47
 
48
+ logging.info('Importing 1000 Questions...')
49
  questions = client.collections.get("Question")
50
  questions.data.insert_many(question_objs)
51
  logging.info('Finished Importing Questions')
52
 
53
  def respond(query):
54
 
 
 
 
 
55
  response = questions.query.near_text(
56
  query=query,
57
+ limit=1
58
  )
59
 
60
  return response.objects[0].properties
 
62
  demo = gr.Interface(fn=respond,
63
  inputs=gr.Textbox(
64
  label="Search the Jeopardy Vector Database",
65
+ info="Enter a Query:",
66
  lines=1,
67
  value="Guitar",
68
  ),