File size: 3,154 Bytes
a4ccfe0
 
247ef7e
77e1c55
a4ccfe0
 
 
247ef7e
a4ccfe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c1f2d6
 
 
a4ccfe0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import gradio as gr
from data_library import embedded_form
import pandas as pd
from embed import sample_embedding

import faiss
embedded_form=embedded_form["train"]
embedded_form.add_faiss_index("embedding")



# gradio function

description="""<center>
<H1 style="background-color:powderblue;">ASK ME SCIENCE RELATED QUESTIONS(BIOLOGY,PHYSICS AND CHEMISTRY)</H1></center>"""


def input_text1(text):

  
  question_embedding =sample_embedding([text])
  question_embedding=question_embedding["embedding"]
  scores, samples = embedded_form.get_nearest_examples(
      "embedding", question_embedding, k=5
    )
  dataframe=pd.DataFrame(samples)
  dataframe["scores"]=scores
  dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)

  return dataframe.loc[0,"support"]



def input_text2(text):

  
  question_embedding =sample_embedding([text])
  question_embedding=question_embedding["embedding"]
  scores, samples = embedded_form.get_nearest_examples(
      "embedding", question_embedding, k=5
    )
  dataframe=pd.DataFrame(samples)
  dataframe["scores"]=scores
  dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)

  return dataframe.loc[1,"support"]


def input_text3(text):

  
  question_embedding =sample_embedding([text])
  question_embedding=question_embedding["embedding"]
  scores, samples = embedded_form.get_nearest_examples(
      "embedding", question_embedding, k=5
    )
  dataframe=pd.DataFrame(samples)
  dataframe["scores"]=scores
  dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)

  return dataframe.loc[2,"support"]


def input_text4(text):

  
  question_embedding =sample_embedding([text])
  question_embedding=question_embedding["embedding"]
  scores, samples = embedded_form.get_nearest_examples(
      "embedding", question_embedding, k=5
    )
  dataframe=pd.DataFrame(samples)
  dataframe["scores"]=scores
  dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)

  return dataframe.loc[3,"support"]

def input_text5(text):

  
  question_embedding =sample_embedding([text])
  question_embedding=question_embedding["embedding"]
  scores, samples = embedded_form.get_nearest_examples(
      "embedding", question_embedding, k=5
    )
  dataframe=pd.DataFrame(samples)
  dataframe["scores"]=scores
  dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)

  return dataframe.loc[4,"support"]


answer1=gr.Interface(input_text1,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 1"))

answer2=gr.Interface(input_text2,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 2"))

answer3=gr.Interface(input_text3,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 3"))


answer4=gr.Interface(input_text4,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 4"))

answer5=gr.Interface(input_text5,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 5"))

demo=gr.Parallel(answer1,answer2,answer3,answer4,answer5,description=description)


if __name__ == "__main__":
    demo.launch(debug=True)