ThePixOne commited on
Commit
fdf52cc
1 Parent(s): dd10f53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -68,9 +68,9 @@ def encode_docs(docs,maxlen = 64, stride = 32):
68
 
69
  embeddings = np.float32(torch.stack(embeddings).transpose(0, 1).cpu())
70
 
71
- np.save("encoded_gradio/emb_{}.npy".format(name),dict(zip(list(range(len(embeddings))),embeddings)))
72
- np.save("encoded_gradio/spans_{}.npy".format(name),dict(zip(list(range(len(spans))),spans)))
73
- np.save("encoded_gradio/file_{}.npy".format(name),dict(zip(list(range(len(file_names))),file_names)))
74
 
75
  return embeddings, spans, file_names
76
 
@@ -81,16 +81,16 @@ def predict(query,data):
81
  now = datetime.now()
82
  current_time = now.strftime("%H:%M:%S")
83
  try:
84
- df = pd.read_csv("HISTORY/{}.csv".format(hash(st)))
85
  return df
86
  except Exception as e:
87
  print(e)
88
  print(st)
89
 
90
  if name_to_save+".txt" in os.listdir("text_gradio"):
91
- doc_emb = np.load('encoded_gradio/emb_{}.npy'.format(name_to_save),allow_pickle='TRUE').item()
92
- doc_text = np.load('encoded_gradio/spans_{}.npy'.format(name_to_save),allow_pickle='TRUE').item()
93
- file_names_dicto = np.load('encoded_gradio/file_{}.npy'.format(name_to_save),allow_pickle='TRUE').item()
94
 
95
  doc_emb = np.array(list(doc_emb.values())).reshape(-1,768)
96
  doc_text = list(doc_text.values())
@@ -105,7 +105,7 @@ def predict(query,data):
105
  doc_emb, doc_text, file_names = encode_docs((name_to_save,text),maxlen = 64, stride = 32)
106
 
107
  doc_emb = doc_emb.reshape(-1, 768)
108
- with open("text_gradio/{}.txt".format(name_to_save),"w",encoding="utf-8") as f:
109
  f.write(text)
110
  start = time.time()
111
  query_emb = encode_query(query)
@@ -154,7 +154,7 @@ def predict(query,data):
154
  f.write(" " + str(current_time))
155
  f.write("\n")
156
  f.close()
157
- df.to_csv("HISTORY/{}.csv".format(hash(st)), index=False)
158
 
159
  return df
160
 
@@ -162,7 +162,6 @@ iface = gr.Interface(
162
 
163
  fn =predict,
164
  inputs = [gr.inputs.Textbox(default="What is Open-domain question answering?"),
165
- gr.inputs.Checkbox(default=True),
166
  gr.inputs.File(),
167
  ],
168
  outputs = [
 
68
 
69
  embeddings = np.float32(torch.stack(embeddings).transpose(0, 1).cpu())
70
 
71
+ np.save("emb_{}.npy".format(name),dict(zip(list(range(len(embeddings))),embeddings)))
72
+ np.save("spans_{}.npy".format(name),dict(zip(list(range(len(spans))),spans)))
73
+ np.save("file_{}.npy".format(name),dict(zip(list(range(len(file_names))),file_names)))
74
 
75
  return embeddings, spans, file_names
76
 
 
81
  now = datetime.now()
82
  current_time = now.strftime("%H:%M:%S")
83
  try:
84
+ df = pd.read_csv("{}.csv".format(hash(st)))
85
  return df
86
  except Exception as e:
87
  print(e)
88
  print(st)
89
 
90
  if name_to_save+".txt" in os.listdir("text_gradio"):
91
+ doc_emb = np.load('emb_{}.npy'.format(name_to_save),allow_pickle='TRUE').item()
92
+ doc_text = np.load('spans_{}.npy'.format(name_to_save),allow_pickle='TRUE').item()
93
+ file_names_dicto = np.load('file_{}.npy'.format(name_to_save),allow_pickle='TRUE').item()
94
 
95
  doc_emb = np.array(list(doc_emb.values())).reshape(-1,768)
96
  doc_text = list(doc_text.values())
 
105
  doc_emb, doc_text, file_names = encode_docs((name_to_save,text),maxlen = 64, stride = 32)
106
 
107
  doc_emb = doc_emb.reshape(-1, 768)
108
+ with open("{}.txt".format(name_to_save),"w",encoding="utf-8") as f:
109
  f.write(text)
110
  start = time.time()
111
  query_emb = encode_query(query)
 
154
  f.write(" " + str(current_time))
155
  f.write("\n")
156
  f.close()
157
+ df.to_csv("{}.csv".format(hash(st)), index=False)
158
 
159
  return df
160
 
 
162
 
163
  fn =predict,
164
  inputs = [gr.inputs.Textbox(default="What is Open-domain question answering?"),
 
165
  gr.inputs.File(),
166
  ],
167
  outputs = [