AhmedEwis commited on
Commit
9440e6a
1 Parent(s): 757b4e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -34
app.py CHANGED
@@ -635,16 +635,6 @@ from langchain.vectorstores.faiss import FAISS
635
  from langchain.text_splitter import RecursiveCharacterTextSplitter
636
  from langchain import OpenAI, VectorDBQA
637
 
638
- # Authenticate with your Hugging Face API key
639
- hf_api = HfApi()
640
- hf_folder = HfFolder()
641
- hf_api.login(hf_folder.get_token('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'))
642
-
643
- # Hugging Face space variables
644
- namespace = "AhmedEwis"
645
- repo_name = "Shagardi_chatbot"
646
- csv_file_path = "questions.csv"
647
-
648
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
649
  texts = text_splitter.split_text(state_of_the_union)
650
 
@@ -659,37 +649,20 @@ chain = load_chain("lc://chains/vector-db-qa/stuff/chain.json", vectorstore=vect
659
  def run_chain(query):
660
  return chain.run(query)
661
 
662
- def download_csv_from_space():
663
- file_url = hf_hub_download(repo_id=f"{namespace}/{repo_name}", filename=csv_file_path)
664
- with open(file_url, "r") as f:
665
- return f.read()
666
-
667
- def save_question_to_csv(question):
668
- csv_data = download_csv_from_space()
669
- csvfile = StringIO(csv_data)
670
- csvfile.seek(0)
671
-
672
- reader = csv.reader(csvfile)
673
- rows = list(reader)
674
-
675
- with open(csv_file_path, 'w', newline='', encoding='utf-8') as f:
676
- writer = csv.writer(f)
677
- for row in rows:
678
- writer.writerow(row)
679
  writer.writerow([question])
680
 
681
- hf_api.upload_file(
682
- path_or_fileobj=csv_file_path,
683
- repo_id=f"{namespace}/{repo_name}",
684
- file_name=csv_file_path,
685
- )
686
-
687
  inputs = gr.inputs.Textbox(lines=1, label="Enter your Question:")
688
  outputs = gr.outputs.Textbox(label="Answer:")
689
 
 
 
 
690
  def run_app(input):
691
  answer = run_chain(input)
692
- save_question_to_csv(input)
693
  return answer
694
 
695
  gr.Interface(fn=run_app, inputs=inputs, outputs=outputs, title="The following is a conversation with a human called Shegardi. Shegardi is helpful, precise, truthful, and very friendly. Also, Shegardi is an employee of Warba Bank, located in Kuwait. Shegardi will only use the information provided to him.").launch()
 
635
  from langchain.text_splitter import RecursiveCharacterTextSplitter
636
  from langchain import OpenAI, VectorDBQA
637
 
 
 
 
 
 
 
 
 
 
 
638
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
639
  texts = text_splitter.split_text(state_of_the_union)
640
 
 
649
  def run_chain(query):
650
  return chain.run(query)
651
 
652
+ def save_question_to_csv(file_path, question):
653
+ with open(file_path, 'a', newline='', encoding='utf-8') as csvfile:
654
+ writer = csv.writer(csvfile)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
  writer.writerow([question])
656
 
 
 
 
 
 
 
657
  inputs = gr.inputs.Textbox(lines=1, label="Enter your Question:")
658
  outputs = gr.outputs.Textbox(label="Answer:")
659
 
660
+ # Provide an absolute path to the CSV file
661
+ csv_file_path = os.path.abspath('questions.csv')
662
+
663
  def run_app(input):
664
  answer = run_chain(input)
665
+ save_question_to_csv(csv_file_path, input)
666
  return answer
667
 
668
  gr.Interface(fn=run_app, inputs=inputs, outputs=outputs, title="The following is a conversation with a human called Shegardi. Shegardi is helpful, precise, truthful, and very friendly. Also, Shegardi is an employee of Warba Bank, located in Kuwait. Shegardi will only use the information provided to him.").launch()