Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from llama_cpp import Llama
|
3 |
|
4 |
-
#
|
5 |
MODEL_URL = "https://huggingface.co/TheBloke/Llama-2-7B-GGML/resolve/main/llama-7B.ggmlv3.q4_0.bin"
|
|
|
6 |
|
7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def omni_ai_chat(user_message, history):
|
9 |
-
llm = Llama(model_path=
|
10 |
-
response = llm(user_message)
|
11 |
return response["choices"][0]["text"].strip()
|
12 |
|
13 |
-
# Set up Gradio chatbot UI
|
14 |
chatbot = gr.ChatInterface(fn=omni_ai_chat, title="OmniAI - Cloud AI",
|
15 |
description="Your personal AI assistant, running entirely in the cloud!",
|
16 |
type="messages") # Fixes deprecated format warning
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
from llama_cpp import Llama
|
4 |
|
5 |
+
# Define model URL & local path
|
6 |
MODEL_URL = "https://huggingface.co/TheBloke/Llama-2-7B-GGML/resolve/main/llama-7B.ggmlv3.q4_0.bin"
|
7 |
+
MODEL_PATH = "/home/user/app/llama-7B.ggmlv3.q4_0.bin" # Local storage path
|
8 |
|
9 |
+
# Function to download model if not present
|
10 |
+
def download_model():
|
11 |
+
if not os.path.exists(MODEL_PATH):
|
12 |
+
print("Downloading model...")
|
13 |
+
response = requests.get(MODEL_URL, stream=True)
|
14 |
+
with open(MODEL_PATH, "wb") as f:
|
15 |
+
for chunk in response.iter_content(chunk_size=8192):
|
16 |
+
f.write(chunk)
|
17 |
+
print("Model downloaded successfully!")
|
18 |
+
|
19 |
+
# Download model before launching OmniAI
|
20 |
+
download_model()
|
21 |
+
|
22 |
+
# Define OmniAI's chat function
|
23 |
def omni_ai_chat(user_message, history):
|
24 |
+
llm = Llama(model_path=MODEL_PATH) # Load locally downloaded model
|
25 |
+
response = llm(user_message)
|
26 |
return response["choices"][0]["text"].strip()
|
27 |
|
28 |
+
# Set up Gradio chatbot UI
|
29 |
chatbot = gr.ChatInterface(fn=omni_ai_chat, title="OmniAI - Cloud AI",
|
30 |
description="Your personal AI assistant, running entirely in the cloud!",
|
31 |
type="messages") # Fixes deprecated format warning
|