Prathamesh Sable commited on
Commit
dc73fb8
·
1 Parent(s): 36b4cec

app setup basic

Browse files
Files changed (3) hide show
  1. .gitignore +7 -0
  2. app.py +87 -0
  3. requirements.txt +17 -0
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ .env
2
+ venv/
3
+ chroma_db
4
+ .vscode
5
+ chroma
6
+ /trash
7
+ uploads/
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask,request, jsonify
2
+ from flask import render_template
3
+ from werkzeug.utils import secure_filename
4
+
5
+ from langchain.document_loaders import DirectoryLoader,PyPDFLoader,UnstructuredWordDocumentLoader,TextLoader,UnstructuredHTMLLoader,UnstructuredMarkdownLoader
6
+
7
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
8
+
9
+ from langchain.embeddings.huggingface import HuggingFaceInferenceAPIEmbeddings
10
+ from langchain_chroma import Chroma
11
+
12
+ import google.generativeai as genai
13
+
14
+ from dotenv import load_dotenv
15
+ import os
16
+ import shutil
17
+
18
+ load_dotenv()
19
+
20
+ HF_TOKEN = os.getenv('HF_TOKEN')
21
+ GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
22
+ CHROMA_PATH = "chroma"
23
+ UPLOAD_FOLDER = "uploads"
24
+
25
+ # Initialize Hugging Face embedding
26
+ hugging_face_ef = HuggingFaceInferenceAPIEmbeddings(
27
+ api_key=HF_TOKEN,
28
+ model_name="sentence-transformers/all-MiniLM-L6-v2"
29
+ )
30
+ genai.configure(api_key=GOOGLE_API_KEY)
31
+ llm_model = genai.GenerativeModel("gemini-1.5-flash")
32
+
33
+ if not os.path.exists(UPLOAD_FOLDER):
34
+ os.makedirs(UPLOAD_FOLDER)
35
+
36
+ app = Flask(__name__)
37
+
38
+
39
+ @app.route('/')
40
+ def index():
41
+ return render_template('index.html') # Serve the HTML file we created
42
+
43
+
44
+ @app.route("/ai",methods=["POST"])
45
+ def aiPost():
46
+ print("Post /ai called")
47
+ json_content = request.json
48
+ query = json_content.get("query")
49
+
50
+ print("Query:",query)
51
+
52
+ response_answer = llm_model.generate_content(query)
53
+ return response_answer.text
54
+
55
+ # add files
56
+ @app.route('/upload', methods=['POST'])
57
+ def upload_files():
58
+ if 'files' not in request.files:
59
+ return jsonify({'error': 'No files in request'}), 400
60
+
61
+ files = request.files.getlist('files')
62
+
63
+ uploaded_files = []
64
+ for file in files:
65
+ if file.filename:
66
+ # Secure the filename
67
+ filename = secure_filename(file.filename)
68
+ file_path = os.path.join(UPLOAD_FOLDER, filename)
69
+ file.save(file_path)
70
+ uploaded_files.append(filename)
71
+
72
+ # Here you can call your RAG pipeline processing function
73
+ # process_pdf(file_path)
74
+
75
+ return jsonify({
76
+ 'message': 'Files uploaded successfully',
77
+ 'files': uploaded_files
78
+ })
79
+
80
+
81
+ def main():
82
+ app.run(host="0.0.0.0",port=8000,debug=True)
83
+
84
+ if __name__ == "__main__":
85
+ main()
86
+
87
+
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ langchain
4
+ langchain-community
5
+ unstructured
6
+ chromadb
7
+ transformers
8
+ huggingface-hub
9
+ requests
10
+ python-dotenv
11
+ langchain-chroma
12
+ sentence_transformers
13
+ google-generativeai
14
+ markdown
15
+ python-docx
16
+ flask
17
+ werkzeug