Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,9 @@ import os
|
|
3 |
import PyPDF2
|
4 |
import pandas as pd
|
5 |
import openai
|
6 |
-
from
|
7 |
-
from
|
8 |
-
from
|
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"]
|
87 |
-
gr.File(file_types=[".txt"]
|
88 |
-
gr.File(file_types=[".csv"]
|
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 |
)
|