Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,26 +2,25 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import subprocess
|
| 4 |
import time
|
| 5 |
-
import
|
| 6 |
|
| 7 |
-
# Start the Ollama server and
|
| 8 |
-
subprocess.Popen(['bash', 'run_ollama.sh'])
|
| 9 |
-
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
with open(ollama_url_file, 'r') as file:
|
| 17 |
-
OLLAMA_URL = file.read().strip()
|
| 18 |
|
| 19 |
console_output = []
|
| 20 |
|
| 21 |
def call_ollama_api(prompt):
|
| 22 |
try:
|
| 23 |
response = requests.post(
|
| 24 |
-
f'{
|
| 25 |
json={"prompt": prompt}
|
| 26 |
)
|
| 27 |
response.raise_for_status() # Raise an exception for HTTP errors
|
|
|
|
| 2 |
import requests
|
| 3 |
import subprocess
|
| 4 |
import time
|
| 5 |
+
import sys
|
| 6 |
|
| 7 |
+
# Start the Ollama server and capture its URL output
|
| 8 |
+
process = subprocess.Popen(['bash', 'run_ollama.sh'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 9 |
+
stdout, stderr = process.communicate()
|
| 10 |
|
| 11 |
+
# Check for errors or retrieve the URL from stdout
|
| 12 |
+
if process.returncode != 0:
|
| 13 |
+
print(f"Error starting Ollama: {stderr.decode()}")
|
| 14 |
+
sys.exit(1)
|
| 15 |
|
| 16 |
+
ollama_url = stdout.decode().strip().split('\n')[-1].split()[-1] # Extract the URL
|
|
|
|
|
|
|
| 17 |
|
| 18 |
console_output = []
|
| 19 |
|
| 20 |
def call_ollama_api(prompt):
|
| 21 |
try:
|
| 22 |
response = requests.post(
|
| 23 |
+
f'{ollama_url}/generate',
|
| 24 |
json={"prompt": prompt}
|
| 25 |
)
|
| 26 |
response.raise_for_status() # Raise an exception for HTTP errors
|