paopaoka3325 commited on
Commit
f3c489d
·
1 Parent(s): 9953cd0

add requiretment

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -32,18 +32,20 @@ def greet(name1, name2, name3, name4):
32
 
33
 
34
 
35
- import site
36
- import os
37
 
38
  def get_package_location(package_name):
39
- for directory in site.getsitepackages():
40
- package_path = os.path.join(directory, package_name)
41
- if os.path.exists(package_path):
42
- return package_path
43
- return 'not found'
44
-
45
- package_name = "ontogpt" # You can replace this with any package name
 
 
46
  location = get_package_location(package_name)
 
47
  # return location
48
  # For the purpose of this example, I'm just returning the values concatenated
49
  return f"Inputs received: {str1}, {str2}, {str3}, {str4}, '--------------', {location}, '--------------', {output_string1},{error_string1},{output_string2},{error_string2},{output}"
 
32
 
33
 
34
 
35
+ import subprocess
 
36
 
37
  def get_package_location(package_name):
38
+ try:
39
+ result = subprocess.check_output(["pip", "show", package_name], text=True)
40
+ for line in result.splitlines():
41
+ if line.startswith("Location:"):
42
+ return line.split(":")[1].strip()
43
+ except:
44
+ return None
45
+
46
+ package_name = "ontogpt" # Replace this with any package name
47
  location = get_package_location(package_name)
48
+
49
  # return location
50
  # For the purpose of this example, I'm just returning the values concatenated
51
  return f"Inputs received: {str1}, {str2}, {str3}, {str4}, '--------------', {location}, '--------------', {output_string1},{error_string1},{output_string2},{error_string2},{output}"