Rafa1986 commited on
Commit
0530099
·
verified ·
1 Parent(s): 8211431

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -3,10 +3,9 @@ import os
3
  import PyPDF2
4
  import pandas as pd
5
  import openai
6
- from langchain.text_splitter import RecursiveCharacterTextSplitter
7
- from langchain.embeddings import OpenAIEmbeddings
8
- from langchain.vectorstores import FAISS
9
- from langchain.llms import OpenAI
10
 
11
  def detect_language(text):
12
  """Detects the language of the input text using OpenAI."""
@@ -70,9 +69,9 @@ def get_answer(question, vector_db):
70
 
71
  def chatbot_interface(pdf_files, txt_files, csv_files, question):
72
  text = ""
73
- text += get_text_from_pdf(pdf_files) if pdf_files else ""
74
- text += get_text_from_txt(txt_files) if txt_files else ""
75
- text += get_text_from_csv(csv_files) if csv_files else ""
76
 
77
  if not text:
78
  return "Please upload files before asking questions."
@@ -83,9 +82,9 @@ def chatbot_interface(pdf_files, txt_files, csv_files, question):
83
  # Gradio interface
84
  demo = gr.Interface(
85
  fn=chatbot_interface,
86
- inputs=[gr.File(file_types=[".pdf"], multiple=True),
87
- gr.File(file_types=[".txt"], multiple=True),
88
- gr.File(file_types=[".csv"], multiple=True),
89
  gr.Textbox(placeholder="Type your question here...")],
90
  outputs=gr.Textbox()
91
  )
 
3
  import PyPDF2
4
  import pandas as pd
5
  import openai
6
+ from langchain_community.embeddings import OpenAIEmbeddings
7
+ from langchain_community.vectorstores import FAISS
8
+ from langchain_community.llms import OpenAI
 
9
 
10
  def detect_language(text):
11
  """Detects the language of the input text using OpenAI."""
 
69
 
70
  def chatbot_interface(pdf_files, txt_files, csv_files, question):
71
  text = ""
72
+ text += get_text_from_pdf([pdf_files]) if pdf_files else ""
73
+ text += get_text_from_txt([txt_files]) if txt_files else ""
74
+ text += get_text_from_csv([csv_files]) if csv_files else ""
75
 
76
  if not text:
77
  return "Please upload files before asking questions."
 
82
  # Gradio interface
83
  demo = gr.Interface(
84
  fn=chatbot_interface,
85
+ inputs=[gr.File(file_types=[".pdf"]),
86
+ gr.File(file_types=[".txt"]),
87
+ gr.File(file_types=[".csv"]),
88
  gr.Textbox(placeholder="Type your question here...")],
89
  outputs=gr.Textbox()
90
  )