HenryY2023 commited on
Commit
7d0b369
·
verified ·
1 Parent(s): 50d6c3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -2
app.py CHANGED
@@ -1,9 +1,39 @@
1
  # app.py
 
 
2
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import gradio as gr
4
  import sqlite3
5
  from datetime import datetime
6
- os.system("install.sh")
7
  from PyPDF2 import PdfReader
8
  from langchain.text_splitter import RecursiveCharacterTextSplitter
9
  from langchain.embeddings import HuggingFaceEmbeddings
@@ -13,7 +43,7 @@ from langchain.prompts import PromptTemplate
13
  from langchain.llms.base import LLM
14
  from typing import Optional, List, Dict, Any
15
  from zhipuai import ZhipuAI
16
- #os.system("install.sh")
17
  # Custom LLM wrapper for Zhipu AI
18
  class ZhipuAILLM(LLM):
19
  client: ZhipuAI
 
1
  # app.py
2
+ import subprocess
3
+ import sys
4
  import os
5
+
6
+ # Run installation commands at startup
7
+ def install_packages():
8
+ print("Starting package installation...")
9
+
10
+ # Upgrade pip
11
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pip"])
12
+
13
+ # Install compatible versions in a specific order
14
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "websockets==10.4"])
15
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "gradio==3.35.0"])
16
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "gradio-client==0.5.0"])
17
+
18
+ # Install the rest of the requirements
19
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "PyPDF2==3.0.1"])
20
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "langchain==0.0.340"])
21
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "faiss-cpu==1.7.4"])
22
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "sentence-transformers==2.3.0"])
23
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "zhipuai>=2.1.0"])
24
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "transformers==4.35.2"])
25
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "torch==2.1.0"])
26
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "huggingface-hub==0.16.4"])
27
+
28
+ print("Package installation completed successfully")
29
+
30
+ # Run the installation
31
+ install_packages()
32
+
33
+ # Now continue with the rest of the app
34
  import gradio as gr
35
  import sqlite3
36
  from datetime import datetime
 
37
  from PyPDF2 import PdfReader
38
  from langchain.text_splitter import RecursiveCharacterTextSplitter
39
  from langchain.embeddings import HuggingFaceEmbeddings
 
43
  from langchain.llms.base import LLM
44
  from typing import Optional, List, Dict, Any
45
  from zhipuai import ZhipuAI
46
+
47
  # Custom LLM wrapper for Zhipu AI
48
  class ZhipuAILLM(LLM):
49
  client: ZhipuAI