J Z commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,58 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def hello():
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
demo = gr.Interface(
|
| 8 |
fn=hello,
|
| 9 |
inputs=None,
|
| 10 |
outputs="text",
|
| 11 |
-
title="
|
| 12 |
)
|
| 13 |
|
| 14 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def find_ollama():
|
| 6 |
+
try:
|
| 7 |
+
# Method 1: Check if it's in the PATH
|
| 8 |
+
which_result = subprocess.run(
|
| 9 |
+
"which ollama",
|
| 10 |
+
shell=True,
|
| 11 |
+
capture_output=True,
|
| 12 |
+
text=True
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
if which_result.returncode == 0 and which_result.stdout.strip():
|
| 16 |
+
return f"Ollama found using 'which': {which_result.stdout.strip()}"
|
| 17 |
+
|
| 18 |
+
# Method 2: Find executable using find command
|
| 19 |
+
find_result = subprocess.run(
|
| 20 |
+
"find / -name ollama -type f 2>/dev/null",
|
| 21 |
+
shell=True,
|
| 22 |
+
capture_output=True,
|
| 23 |
+
text=True
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
if find_result.stdout.strip():
|
| 27 |
+
paths = find_result.stdout.strip().split('\n')
|
| 28 |
+
return f"Ollama found using 'find':\n{'\n'.join(paths)}"
|
| 29 |
+
|
| 30 |
+
# Method 3: Check common installation locations
|
| 31 |
+
common_locations = [
|
| 32 |
+
"/usr/bin/ollama",
|
| 33 |
+
"/usr/local/bin/ollama",
|
| 34 |
+
"/opt/ollama/ollama",
|
| 35 |
+
"/home/user/.local/bin/ollama"
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
for location in common_locations:
|
| 39 |
+
if os.path.exists(location) and os.access(location, os.X_OK):
|
| 40 |
+
return f"Ollama found at common location: {location}"
|
| 41 |
+
|
| 42 |
+
return "Ollama executable not found. It might not be installed or might be in an unusual location."
|
| 43 |
+
|
| 44 |
+
except Exception as e:
|
| 45 |
+
return f"Error while searching for Ollama: {str(e)}"
|
| 46 |
|
| 47 |
def hello():
|
| 48 |
+
ollama_location = find_ollama()
|
| 49 |
+
return f"Space is running successfully!\n\n{ollama_location}"
|
| 50 |
|
| 51 |
demo = gr.Interface(
|
| 52 |
fn=hello,
|
| 53 |
inputs=None,
|
| 54 |
outputs="text",
|
| 55 |
+
title="Ollama Finder"
|
| 56 |
)
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|