Spaces:
Sleeping
Sleeping
swamisharan
commited on
Commit
•
2bd9b9e
1
Parent(s):
b5bfd39
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import os
|
2 |
import torch
|
3 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
@@ -10,13 +11,12 @@ from langchain.document_loaders import PDFMinerLoader
|
|
10 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
11 |
from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction
|
12 |
import chromadb
|
13 |
-
import
|
14 |
-
from gradio.components import File
|
15 |
|
16 |
# Define Chroma Settings
|
17 |
CHROMA_SETTINGS = {
|
18 |
"chroma_db_impl": "duckdb+parquet",
|
19 |
-
"persist_directory":
|
20 |
"anonymized_telemetry": False
|
21 |
}
|
22 |
|
@@ -64,22 +64,21 @@ def qa_llm():
|
|
64 |
|
65 |
return qa
|
66 |
|
67 |
-
def process_answer(file):
|
68 |
-
|
69 |
-
|
|
|
70 |
qa = qa_llm()
|
71 |
-
generated_text = qa(
|
72 |
answer = generated_text["result"]
|
73 |
return answer
|
74 |
|
75 |
-
#
|
76 |
-
|
77 |
-
fn=process_answer,
|
78 |
-
inputs=
|
79 |
-
outputs="text"
|
80 |
-
title="Chatbot",
|
81 |
-
description="Please enter your question:"
|
82 |
)
|
83 |
|
84 |
-
# Launch the
|
85 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
import os
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
11 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
12 |
from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction
|
13 |
import chromadb
|
14 |
+
import tempfile
|
|
|
15 |
|
16 |
# Define Chroma Settings
|
17 |
CHROMA_SETTINGS = {
|
18 |
"chroma_db_impl": "duckdb+parquet",
|
19 |
+
"persist_directory": tempfile.mkdtemp(), # Use a temporary directory
|
20 |
"anonymized_telemetry": False
|
21 |
}
|
22 |
|
|
|
64 |
|
65 |
return qa
|
66 |
|
67 |
+
def process_answer(file, instruction):
|
68 |
+
# Ingest the data from the uploaded PDF
|
69 |
+
data_ingestion(file.name)
|
70 |
+
# Process the question
|
71 |
qa = qa_llm()
|
72 |
+
generated_text = qa(instruction)
|
73 |
answer = generated_text["result"]
|
74 |
return answer
|
75 |
|
76 |
+
# Define Gradio interface
|
77 |
+
iface = gr.Interface(
|
78 |
+
fn=process_answer,
|
79 |
+
inputs=["file", "text"],
|
80 |
+
outputs="text"
|
|
|
|
|
81 |
)
|
82 |
|
83 |
+
# Launch the interface
|
84 |
+
iface.launch()
|