HonestAnnie commited on
Commit
dde2538
1 Parent(s): 4699e8e

english only now

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -5,9 +5,9 @@ from sentence_transformers import SentenceTransformer
5
  import spaces
6
 
7
  client = chromadb.PersistentClient(path="./chroma")
8
- collection_de = client.get_collection(name="phil_de")
9
  collection_en = client.get_collection(name="phil_en")
10
- authors_list_de = ["Ludwig Wittgenstein", "Sigmund Freud", "Marcus Aurelius", "Friedrich Nietzsche", "Epiktet", "Ernst Jünger", "Georg Christoph Lichtenberg", "Balthasar Gracian", "Hannah Arendt", "Erich Fromm", "Albert Camus"]
11
  authors_list_en = ["Friedrich Nietzsche", "Joscha Bach"]
12
 
13
  @spaces.GPU
@@ -47,26 +47,27 @@ def query_chroma(collection, embedding, authors):
47
 
48
  with gr.Blocks(css=".custom-markdown { border: 1px solid #ccc; padding: 10px; border-radius: 5px; }") as demo:
49
  gr.Markdown("Enter your query, filter authors (default is all), click **Search** to search. Delimit multiple queries with semicola; since there is a quota for each user (based on IP) it makes sense to query in batches. The search takes around 40 seconds, regardless of the number of queries, because the embedding model needs to be loaded to a GPU each time.")
50
- database_inp = gr.Dropdown(label="Database", choices=["German", "English"], value="German")
51
- author_inp = gr.Dropdown(label="Authors", choices=authors_list_de, multiselect=True)
52
- inp = gr.Textbox(label="Query", placeholder="Wie kann ich gesund leben und bedeutet Gesundheit für jeden das gleiche?; Was ist der Sinn des Lebens?; ...")
53
  btn = gr.Button("Search")
54
  results = gr.State()
55
 
56
- def update_authors(database):
57
- return gr.update(choices=authors_list_de if database == "German" else authors_list_en)
58
 
59
- database_inp.change(
60
- fn=lambda database: update_authors(database),
61
- inputs=[database_inp],
62
- outputs=[author_inp]
63
- )
64
 
65
  def perform_query(queries, authors, database):
66
  task = "Given a question, retrieve passages that answer the question"
67
- queries = queries.split(';')
68
  embeddings = get_embeddings(queries, task)
69
- collection = collection_de if database == "German" else collection_en
 
70
  results_data = []
71
  for query, embedding in zip(queries, embeddings):
72
  res = query_chroma(collection, embedding, authors)
@@ -75,7 +76,7 @@ with gr.Blocks(css=".custom-markdown { border: 1px solid #ccc; padding: 10px; bo
75
 
76
  btn.click(
77
  perform_query,
78
- inputs=[inp, author_inp, database_inp],
79
  outputs=[results]
80
  )
81
 
 
5
  import spaces
6
 
7
  client = chromadb.PersistentClient(path="./chroma")
8
+ #collection_de = client.get_collection(name="phil_de")
9
  collection_en = client.get_collection(name="phil_en")
10
+ #authors_list_de = ["Ludwig Wittgenstein", "Sigmund Freud", "Marcus Aurelius", "Friedrich Nietzsche", "Epiktet", "Ernst Jünger", "Georg Christoph Lichtenberg", "Balthasar Gracian", "Hannah Arendt", "Erich Fromm", "Albert Camus"]
11
  authors_list_en = ["Friedrich Nietzsche", "Joscha Bach"]
12
 
13
  @spaces.GPU
 
47
 
48
  with gr.Blocks(css=".custom-markdown { border: 1px solid #ccc; padding: 10px; border-radius: 5px; }") as demo:
49
  gr.Markdown("Enter your query, filter authors (default is all), click **Search** to search. Delimit multiple queries with semicola; since there is a quota for each user (based on IP) it makes sense to query in batches. The search takes around 40 seconds, regardless of the number of queries, because the embedding model needs to be loaded to a GPU each time.")
50
+ #database_inp = gr.Dropdown(label="Database", choices=["German", "English"], value="German")
51
+ author_inp = gr.Dropdown(label="Authors", choices=authors_list_en, multiselect=True)
52
+ inp = gr.Textbox(label="Query", placeholder="How can I live a healthy life?; How can I improve my ability to focus?; What is the meaning of life?; ...")
53
  btn = gr.Button("Search")
54
  results = gr.State()
55
 
56
+ #def update_authors(database):
57
+ # return gr.update(choices=authors_list_de if database == "German" else authors_list_en)
58
 
59
+ #database_inp.change(
60
+ # fn=lambda database: update_authors(database),
61
+ # inputs=[database_inp],
62
+ # outputs=[author_inp]
63
+ #)
64
 
65
  def perform_query(queries, authors, database):
66
  task = "Given a question, retrieve passages that answer the question"
67
+ queries = [query.strip() for query in queries.split(';')]
68
  embeddings = get_embeddings(queries, task)
69
+ #collection = collection_de if database == "German" else collection_en
70
+ collection = collection_en
71
  results_data = []
72
  for query, embedding in zip(queries, embeddings):
73
  res = query_chroma(collection, embedding, authors)
 
76
 
77
  btn.click(
78
  perform_query,
79
+ inputs=[inp, author_inp],
80
  outputs=[results]
81
  )
82