MoiMoi-01 commited on
Commit
91abf63
Β·
verified Β·
1 Parent(s): c57e63e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -17
app.py CHANGED
@@ -3,27 +3,18 @@ import subprocess
3
  import gradio as gr
4
  import ollama
5
 
6
- # Ensure Ollama is installed
7
  def install_ollama():
8
  try:
9
- subprocess.run(["ollama", "--version"], check=True)
10
  print("βœ… Ollama is already installed.")
11
- except FileNotFoundError:
12
- print("πŸš€ Installing Ollama...")
13
- subprocess.run(["curl", "-fsSL", "https://ollama.com/install.sh", "|", "sh"], shell=True, check=True)
 
14
  print("βœ… Ollama installed successfully!")
15
 
16
- # Start Ollama if it's not running
17
- def start_ollama():
18
- try:
19
- subprocess.run(["pgrep", "-f", "ollama"], check=True)
20
- print("βœ… Ollama is already running.")
21
- except subprocess.CalledProcessError:
22
- print("πŸš€ Starting Ollama server...")
23
- subprocess.Popen(["ollama", "serve"])
24
- print("βœ… Ollama started.")
25
-
26
- # Ensure model is downloaded to models/ folder
27
  MODEL_NAME = "deepseek-llm-7b"
28
  MODEL_PATH = f"models/{MODEL_NAME}"
29
 
@@ -43,7 +34,6 @@ def chat_response(user_input):
43
 
44
  # Run setup
45
  install_ollama()
46
- start_ollama()
47
  download_model()
48
 
49
  # Create Gradio Interface
 
3
  import gradio as gr
4
  import ollama
5
 
6
+ # Ensure ollama is installed via pip
7
  def install_ollama():
8
  try:
9
+ import ollama
10
  print("βœ… Ollama is already installed.")
11
+ except ImportError:
12
+ print("πŸš€ Installing Ollama via pip...")
13
+ subprocess.run(["pip", "install", "ollama"], check=True)
14
+ import ollama # Re-import after installation
15
  print("βœ… Ollama installed successfully!")
16
 
17
+ # Ensure model is downloaded
 
 
 
 
 
 
 
 
 
 
18
  MODEL_NAME = "deepseek-llm-7b"
19
  MODEL_PATH = f"models/{MODEL_NAME}"
20
 
 
34
 
35
  # Run setup
36
  install_ollama()
 
37
  download_model()
38
 
39
  # Create Gradio Interface