YchKhan commited on
Commit
4e2fbfe
Β·
1 Parent(s): 4897612

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -432,11 +432,20 @@ def gpt_answer(api_key, query, model="gpt-3.5-turbo-1106", system_prompt="Use th
432
 
433
  def add_line_breaks(input_string, line_length=100):
434
  lines = []
435
- input_string=input_string.split("\n---\n[Sources]")[0]
436
- for i in range(0, len(input_string), line_length):
437
- line = input_string[i:i+line_length]
438
  lines.append(line)
439
- return '\n'.join(lines)
 
 
 
 
 
 
 
 
 
440
 
441
  def ask_df(df, api_key, model, ui_session_id):
442
  answers = []
@@ -454,11 +463,8 @@ def ask_df(df, api_key, model, ui_session_id):
454
  docs = db.similarity_search(question)
455
  references = '\n******************************\n'.join([d.page_content for d in docs])
456
  print(f"REFERENCES: {references}")
457
- sources_file = f"{secrets.token_urlsafe(16)}.txt"
458
- with open(sources_file, 'w') as file:
459
- file.write(references)
460
  try:
461
- source = f"https://organizedprogrammers-docgpt-table.hf.space/file={sources_file}"
462
  except:
463
  source = "ERROR WHILE GETTING THE SOURCES FILE"
464
  query = f"## USER QUESTION:\n{question}\n\n## REFERENCES:\n{references}\n\nANSWER:\n\n"
 
432
 
433
  def add_line_breaks(input_string, line_length=100):
434
  lines = []
435
+ to_break=input_string.split("\n---\n[Sources]")[0]
436
+ for i in range(0, len(to_break), line_length):
437
+ line = to_break[i:i+line_length]
438
  lines.append(line)
439
+ return '\n'.join(lines)+input_string[len(to_break)-1:]
440
+
441
+
442
+
443
+ def upload_text_file(content):
444
+ data = {"content": content, "syntax": "text", "expiry_days": 1}
445
+ headers = {"User-Agent": "Sources"}
446
+ r = requests.post("https://dpaste.com/api/", data=data, headers=headers)
447
+ return r.text + ".txt"
448
+
449
 
450
  def ask_df(df, api_key, model, ui_session_id):
451
  answers = []
 
463
  docs = db.similarity_search(question)
464
  references = '\n******************************\n'.join([d.page_content for d in docs])
465
  print(f"REFERENCES: {references}")
 
 
 
466
  try:
467
+ source = upload_text_file(references)
468
  except:
469
  source = "ERROR WHILE GETTING THE SOURCES FILE"
470
  query = f"## USER QUESTION:\n{question}\n\n## REFERENCES:\n{references}\n\nANSWER:\n\n"