vjain commited on
Commit
18e6a04
1 Parent(s): 78c1787

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -36,13 +36,13 @@ dataframes = {
36
 
37
  #df = pd.read_csv("TA_embeddings.csv")
38
  #df["embedding"]=df["embedding"].apply(eval).apply(np.array)
39
- def reply(input, csv_dropdown):
40
  try:
41
- #if dataset_name not in dataframes:
42
- # return "Invalid dataset selected. Please select a valid dataset."
43
  if not input:
44
  return "Please Enter a Question to get an Answer"
45
- df = csv_dropdown
46
  input = input
47
  input_vector = generate_embeddings(input, model_id,hf_token)
48
  df["similarities"]=df["embedding"].apply(lambda x: cosine_similarity([x],[input_vector])[0][0])
@@ -69,20 +69,15 @@ def reply(input, csv_dropdown):
69
  model="text-davinci-003"
70
  )["choices"][0]["text"].strip(" \n")
71
  return response
72
-
73
  except Exception as e:
74
  return f"An error occurred: {e}"
75
-
76
-
77
-
78
-
79
 
80
  csv_dropdown = gr.inputs.Dropdown(
81
- label="Select the Book",
82
- choices=["AP_Bio", "AP_Physics"],
83
- default="AP_Bio"
84
 
85
- )
86
  input_text = gr.inputs.Textbox(
87
  label="Enter your questions here",
88
  placeholder="E.g. What is DNA?",
 
36
 
37
  #df = pd.read_csv("TA_embeddings.csv")
38
  #df["embedding"]=df["embedding"].apply(eval).apply(np.array)
39
+ def reply(input, dataset_name):
40
  try:
41
+ if dataset_name not in dataframes:
42
+ return "Invalid dataset selected. Please select a valid dataset."
43
  if not input:
44
  return "Please Enter a Question to get an Answer"
45
+ df = dataframes(dataset_name)
46
  input = input
47
  input_vector = generate_embeddings(input, model_id,hf_token)
48
  df["similarities"]=df["embedding"].apply(lambda x: cosine_similarity([x],[input_vector])[0][0])
 
69
  model="text-davinci-003"
70
  )["choices"][0]["text"].strip(" \n")
71
  return response
 
72
  except Exception as e:
73
  return f"An error occurred: {e}"
 
 
 
 
74
 
75
  csv_dropdown = gr.inputs.Dropdown(
76
+ label="Select the Book",
77
+ choices=["AP_Bio", "AP_Physics"],
78
+ default="AP_Bio"
79
 
80
+ )
81
  input_text = gr.inputs.Textbox(
82
  label="Enter your questions here",
83
  placeholder="E.g. What is DNA?",