Spaces:
Build error
Build error
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061622345678model = "gemma2:27b"
import os
os.system("curl https://ollama.ai/install.sh | sh")
import nest_asyncionest_asyncio.apply()
import asyncio
# Run Async Ollama# Taken from: https://stackoverflow.com/questions/77697302/how-to-run-ollama-in-google-colab# NB: You may need to set these depending and get cuda working depending which backend you are running.# Set environment variable for NVIDIA library# Set environment variables for CUDAos.environ['PATH'] += ':/usr/local/cuda/bin'# Set LD_LIBRARY_PATH to include both /usr/lib64-nvidia and CUDA lib directoriesos.environ['LD_LIBRARY_PATH'] = '/usr/lib64-nvidia:/usr/local/cuda/lib64'
async def run_process(cmd): print('>>> starting', *cmd) process = await asyncio.create_subprocess_exec( *cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE )
# define an async pipe function async def pipe(lines): async for line in lines: print(line.decode().strip())
await asyncio.gather( pipe(process.stdout), pipe(process.stderr), )
# call it await asyncio.gather(pipe(process.stdout), pipe(process.stderr))
import threading
async def start_ollama_serve(): await run_process(['ollama', 'serve'])
def run_async_in_thread(loop, coro): asyncio.set_event_loop(loop) loop.run_until_complete(coro) loop.close()
# Create a new event loop that will run in a new threadnew_loop = asyncio.new_event_loop()
# Start ollama serve in a separate thread so the cell won't block executionthread = threading.Thread(target=run_async_in_thread, args=(new_loop, start_ollama_serve()))thread.start()
# Load up model
os.system(f"ollama pull {model}")
import ollamaimport osollama_path="/usr/local/lib/python3.10/site-packages/ollama"os.system(f"{ollama_path} ollama pull {model}")
import copyimport gradio as grapp.py+4-61