makhdoomnaeem commited on
Commit
70049a5
·
verified ·
1 Parent(s): 3a08f74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -10,14 +10,21 @@ from language_tool_python.download_lt import download_lt
10
  def install_java():
11
  try:
12
  # Check if Java is installed
13
- subprocess.run(["java", "-version"], check=True, capture_output=True)
14
- st.write("Java is already installed.")
 
15
  except FileNotFoundError:
16
  # Install Java
17
  st.write("Java is not installed. Installing now...")
18
  subprocess.run(["apt-get", "update"], check=True)
19
- subprocess.run(["apt-get", "install", "-y", "default-jre"], check=True)
20
  st.write("Java installed successfully.")
 
 
 
 
 
 
21
 
22
  # Function to initialize LanguageTool
23
  def initialize_language_tool():
@@ -31,7 +38,7 @@ def initialize_language_tool():
31
  download_lt() # Retry downloading the LanguageTool files
32
  return initialize_language_tool()
33
  except Exception as e:
34
- st.error(f"Error initializing LanguageTool: {e}")
35
  raise e
36
 
37
  # Run Java installation check
@@ -46,8 +53,8 @@ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
46
  tool = None
47
  try:
48
  tool = initialize_language_tool()
49
- except Exception as e:
50
- st.error("Unable to initialize LanguageTool. Please ensure all dependencies are installed and configured.")
51
 
52
  # Helper Functions
53
  def add_human_noise(output_text):
 
10
  def install_java():
11
  try:
12
  # Check if Java is installed
13
+ st.write("Checking Java installation...")
14
+ result = subprocess.run(["java", "-version"], check=True, capture_output=True, text=True)
15
+ st.write("Java is already installed:", result.stderr.strip())
16
  except FileNotFoundError:
17
  # Install Java
18
  st.write("Java is not installed. Installing now...")
19
  subprocess.run(["apt-get", "update"], check=True)
20
+ subprocess.run(["apt-get", "install", "-y", "default-jdk"], check=True) # Install JDK instead of JRE
21
  st.write("Java installed successfully.")
22
+ # Verify Java installation again
23
+ try:
24
+ subprocess.run(["java", "-version"], check=True, capture_output=True)
25
+ except Exception as e:
26
+ st.error("Java installation failed. Please check your system configuration.")
27
+ raise e
28
 
29
  # Function to initialize LanguageTool
30
  def initialize_language_tool():
 
38
  download_lt() # Retry downloading the LanguageTool files
39
  return initialize_language_tool()
40
  except Exception as e:
41
+ st.error(f"Unable to initialize LanguageTool. Error: {e}")
42
  raise e
43
 
44
  # Run Java installation check
 
53
  tool = None
54
  try:
55
  tool = initialize_language_tool()
56
+ except Exception:
57
+ st.error("Unable to initialize LanguageTool. Please ensure Java is installed, and all dependencies are configured.")
58
 
59
  # Helper Functions
60
  def add_human_noise(output_text):