Spaces:
Build error
Build error
LawalAfeez
commited on
Commit
•
a4ccfe0
1
Parent(s):
8a12715
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from data_library import embedded_form
|
3 |
+
|
4 |
+
import faiss
|
5 |
+
embedded_form=embedded_form["train"]
|
6 |
+
embedded_form.load_faiss_index('embeddings', 'my_index.faiss')
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
# gradio function
|
11 |
+
|
12 |
+
description="""<center>
|
13 |
+
<H1 style="background-color:powderblue;">ASK ME SCIENCE RELATED QUESTIONS(BIOLOGY,PHYSICS AND CHEMISTRY)</H1></center>"""
|
14 |
+
|
15 |
+
|
16 |
+
def input_text1(text):
|
17 |
+
|
18 |
+
|
19 |
+
question_embedding =sample_embedding([text])
|
20 |
+
question_embedding=question_embedding["embedding"]
|
21 |
+
scores, samples = embedded_form.get_nearest_examples(
|
22 |
+
"embedding", question_embedding, k=5
|
23 |
+
)
|
24 |
+
dataframe=pd.DataFrame(samples)
|
25 |
+
dataframe["scores"]=scores
|
26 |
+
dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)
|
27 |
+
|
28 |
+
return dataframe.loc[0,"support"]
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
def input_text2(text):
|
33 |
+
|
34 |
+
|
35 |
+
question_embedding =sample_embedding([text])
|
36 |
+
question_embedding=question_embedding["embedding"]
|
37 |
+
scores, samples = embedded_form.get_nearest_examples(
|
38 |
+
"embedding", question_embedding, k=5
|
39 |
+
)
|
40 |
+
dataframe=pd.DataFrame(samples)
|
41 |
+
dataframe["scores"]=scores
|
42 |
+
dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)
|
43 |
+
|
44 |
+
return dataframe.loc[1,"support"]
|
45 |
+
|
46 |
+
|
47 |
+
def input_text3(text):
|
48 |
+
|
49 |
+
|
50 |
+
question_embedding =sample_embedding([text])
|
51 |
+
question_embedding=question_embedding["embedding"]
|
52 |
+
scores, samples = embedded_form.get_nearest_examples(
|
53 |
+
"embedding", question_embedding, k=5
|
54 |
+
)
|
55 |
+
dataframe=pd.DataFrame(samples)
|
56 |
+
dataframe["scores"]=scores
|
57 |
+
dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)
|
58 |
+
|
59 |
+
return dataframe.loc[2,"support"]
|
60 |
+
|
61 |
+
|
62 |
+
def input_text4(text):
|
63 |
+
|
64 |
+
|
65 |
+
question_embedding =sample_embedding([text])
|
66 |
+
question_embedding=question_embedding["embedding"]
|
67 |
+
scores, samples = embedded_form.get_nearest_examples(
|
68 |
+
"embedding", question_embedding, k=5
|
69 |
+
)
|
70 |
+
dataframe=pd.DataFrame(samples)
|
71 |
+
dataframe["scores"]=scores
|
72 |
+
dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)
|
73 |
+
|
74 |
+
return dataframe.loc[3,"support"]
|
75 |
+
|
76 |
+
def input_text5(text):
|
77 |
+
|
78 |
+
|
79 |
+
question_embedding =sample_embedding([text])
|
80 |
+
question_embedding=question_embedding["embedding"]
|
81 |
+
scores, samples = embedded_form.get_nearest_examples(
|
82 |
+
"embedding", question_embedding, k=5
|
83 |
+
)
|
84 |
+
dataframe=pd.DataFrame(samples)
|
85 |
+
dataframe["scores"]=scores
|
86 |
+
dataframe=dataframe.sort_values("scores",ascending=False).reset_index(drop=True)
|
87 |
+
|
88 |
+
return dataframe.loc[4,"support"]
|
89 |
+
|
90 |
+
|
91 |
+
answer1=gr.Interface(input_text1,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 1"))
|
92 |
+
|
93 |
+
answer2=gr.Interface(input_text2,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 2"))
|
94 |
+
|
95 |
+
answer3=gr.Interface(input_text3,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 3"))
|
96 |
+
|
97 |
+
|
98 |
+
answer4=gr.Interface(input_text4,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 4"))
|
99 |
+
|
100 |
+
answer5=gr.Interface(input_text5,inputs=gr.Textbox(label="Question"),outputs=gr.Textbox(label="Support 5"))
|
101 |
+
|
102 |
+
demo=gr.Parallel(answer1,answer2,answer3,answer4,answer5,description=description)
|
103 |
+
|
104 |
+
demo.launch()
|
105 |
+
|
106 |
+
|