Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,29 +2,35 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import subprocess
|
4 |
import time
|
|
|
5 |
|
6 |
# Start the Ollama server and wait for it to output the URL
|
7 |
subprocess.Popen(['bash', 'run_ollama.sh'])
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Read the URL from the file
|
11 |
-
with open(
|
12 |
OLLAMA_URL = file.read().strip()
|
13 |
|
14 |
console_output = []
|
15 |
|
16 |
def call_ollama_api(prompt):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
22 |
result = response.json()
|
23 |
output = result.get('text', '')
|
24 |
console_output.append(f"Prompt: {prompt}\nResponse: {output}")
|
25 |
return output
|
26 |
-
|
27 |
-
error_message = f"Error: {
|
28 |
console_output.append(error_message)
|
29 |
return error_message
|
30 |
|
@@ -51,4 +57,5 @@ console_iface = gr.Interface(
|
|
51 |
description="See the console outputs here."
|
52 |
)
|
53 |
|
|
|
54 |
gr.TabbedInterface([iface, console_iface], ["Chat", "Console"]).launch()
|
|
|
2 |
import requests
|
3 |
import subprocess
|
4 |
import time
|
5 |
+
import os
|
6 |
|
7 |
# Start the Ollama server and wait for it to output the URL
|
8 |
subprocess.Popen(['bash', 'run_ollama.sh'])
|
9 |
+
ollama_url_file = 'ollama_url.txt'
|
10 |
+
|
11 |
+
# Wait for the server URL file to be created
|
12 |
+
while not os.path.exists(ollama_url_file):
|
13 |
+
time.sleep(1)
|
14 |
|
15 |
# Read the URL from the file
|
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'{OLLAMA_URL}/generate',
|
25 |
+
json={"prompt": prompt}
|
26 |
+
)
|
27 |
+
response.raise_for_status() # Raise an exception for HTTP errors
|
28 |
result = response.json()
|
29 |
output = result.get('text', '')
|
30 |
console_output.append(f"Prompt: {prompt}\nResponse: {output}")
|
31 |
return output
|
32 |
+
except requests.exceptions.RequestException as e:
|
33 |
+
error_message = f"Error: {e}"
|
34 |
console_output.append(error_message)
|
35 |
return error_message
|
36 |
|
|
|
57 |
description="See the console outputs here."
|
58 |
)
|
59 |
|
60 |
+
# Launch a tabbed interface
|
61 |
gr.TabbedInterface([iface, console_iface], ["Chat", "Console"]).launch()
|