zeyadahmedd commited on
Commit
1f6f7c0
1 Parent(s): 2022372

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -37
app.py CHANGED
@@ -1,39 +1,39 @@
1
  import gradio as gr
2
- from sentence_transformers import SentenceTransformer, util
3
-
4
- model_name = 'nq-distilbert-base-v1'
5
- bi_encoder = SentenceTransformer("./")
6
- top_k = 5
7
- sentences = [
8
- "a happy person is a person how can do what he want with his money",
9
- "That is a happy dog ho bark alot",
10
- "Today is a sunny day so that a happy person can walk on the street"
11
- ]
12
- # vector embeddings created from dataset
13
- corpus_embeddings = bi_encoder.encode(sentences, convert_to_tensor=True, show_progress_bar=True)
14
-
15
- def search(query):
16
- # Encode the query using the bi-encoder and find potentially relevant passages
17
- question_embedding = bi_encoder.encode(query)
18
- hits = util.semantic_search(question_embedding, corpus_embeddings, top_k=top_k)
19
- hits = hits[0] # Get the hits for the first query
20
-
21
- # Output of top-k hits
22
- print("Input question:", query)
23
- print("Results")
24
- for hit in hits:
25
- print("\t{:.3f}\t{}".format(hit['score'], sentences[hit['corpus_id']]))
26
- return hits
27
-
28
- def greet(name):
29
- hittt = search(query=name)
30
- x=dict()
31
- for hit in hittt:
32
- score=hit['score']
33
- sentence=sentences[hit['corpus_id']]
34
- buffer={sentence:score}
35
- x.update(buffer)
36
- return x
37
  import dill
38
  def greet1(data):
39
  # pdf=data.get('pdf')
@@ -49,8 +49,8 @@ iface = gr.Blocks()
49
  with iface:
50
  name = gr.Textbox(label="Name")
51
  output = gr.Textbox(label="Output Box")
52
- greet_btn = gr.Button("Greet")
53
- greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
54
  greet1_btn = gr.Button("Greet1")
55
  greet1_btn.click(fn=greet1, inputs=name, outputs=output, api_name="testing")
56
 
 
1
  import gradio as gr
2
+ # from sentence_transformers import SentenceTransformer, util
3
+ #
4
+ # model_name = 'nq-distilbert-base-v1'
5
+ # bi_encoder = SentenceTransformer("./")
6
+ # top_k = 5
7
+ # sentences = [
8
+ # "a happy person is a person how can do what he want with his money",
9
+ # "That is a happy dog ho bark alot",
10
+ # "Today is a sunny day so that a happy person can walk on the street"
11
+ # ]
12
+ # # vector embeddings created from dataset
13
+ # corpus_embeddings = bi_encoder.encode(sentences, convert_to_tensor=True, show_progress_bar=True)
14
+ #
15
+ # def search(query):
16
+ # # Encode the query using the bi-encoder and find potentially relevant passages
17
+ # question_embedding = bi_encoder.encode(query)
18
+ # hits = util.semantic_search(question_embedding, corpus_embeddings, top_k=top_k)
19
+ # hits = hits[0] # Get the hits for the first query
20
+ #
21
+ # # Output of top-k hits
22
+ # print("Input question:", query)
23
+ # print("Results")
24
+ # for hit in hits:
25
+ # print("\t{:.3f}\t{}".format(hit['score'], sentences[hit['corpus_id']]))
26
+ # return hits
27
+ #
28
+ # def greet(name):
29
+ # hittt = search(query=name)
30
+ # x=dict()
31
+ # for hit in hittt:
32
+ # score=hit['score']
33
+ # sentence=sentences[hit['corpus_id']]
34
+ # buffer={sentence:score}
35
+ # x.update(buffer)
36
+ # return x
37
  import dill
38
  def greet1(data):
39
  # pdf=data.get('pdf')
 
49
  with iface:
50
  name = gr.Textbox(label="Name")
51
  output = gr.Textbox(label="Output Box")
52
+ # greet_btn = gr.Button("Greet")
53
+ # greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
54
  greet1_btn = gr.Button("Greet1")
55
  greet1_btn.click(fn=greet1, inputs=name, outputs=output, api_name="testing")
56