Entz's picture
Update app.py
82165ef verified
raw
history blame
2.38 kB
import os
import threading
import time
import subprocess
print("Expanding user path for Ollama")
OLLAMA = os.path.expanduser("~/ollama")
print("Checking if Ollama exists at the path")
if not os.path.exists(OLLAMA):
print("Ollama not found, downloading it")
subprocess.run("curl -L https://ollama.com/download/ollama-linux-amd64 -o ~/ollama", shell=True)
os.chmod(OLLAMA, 0o755)
def ollama_service_thread():
print("Starting Ollama service thread")
subprocess.run("~/ollama serve", shell=True)
print("Creating and starting Ollama service thread")
OLLAMA_SERVICE_THREAD = threading.Thread(target=ollama_service_thread)
OLLAMA_SERVICE_THREAD.start()
print("Giving Ollama serve a moment to start")
time.sleep(10)
print("Setting model to 'llama3'")
model = "llama3"
print(f"Pulling model {model}")
subprocess.run(f"~/ollama pull {model}", shell=True)
################################################
################################################
import copy
import gradio as gr
from ollama import Client
print("Initializing Ollama client")
client = Client(host='http://localhost:11435', timeout=60)
print("Getting Hugging Face token and model ID from environment variables")
HF_TOKEN = os.environ.get("HF_TOKEN", None)
MODEL_ID = os.environ.get("MODEL_ID", "meta-llama/Meta-Llama-3-8B")
MODEL_NAME = MODEL_ID.split("/")[-1]
print("Setting up title and description for Gradio interface")
TITLE = "<h1><center>ollama-Chat</center></h1>"
DESCRIPTION = f"""
<h3>MODEL: <a href="https://hf.co/{MODEL_ID}">{MODEL_NAME}</a></h3>
<p>Running on Ollama backend.</p>
"""
CSS = """
.duplicate-button {
margin: auto !important;
color: white !important;
background: black !important;
border-radius: 100vh !important;
}
h3 {
text-align: center;
}
"""
import streamlit as st
#from llama_index.llms.ollama import Ollama
from myollama import Ollama
def main():
st.title("Ollama LLM Demo")
# Get user input
prompt = st.text_input("Enter your prompt:", "What is the capital of France?")
if st.button("Get Response"):
# Create an instance of the Ollama class
llm = Ollama(model="llama2", request_timeout=60.0)
# Get the response from the LLM
response = llm.complete(prompt)
# Display the response
st.write(response)
if __name__ == "__main__":
main()