Spaces:
Build error
Build error
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) | |