Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
|
|
3 |
import requests
|
4 |
from llama_cpp import Llama
|
5 |
|
6 |
# Define model URL & local path
|
7 |
MODEL_URL = "https://huggingface.co/TheBloke/Llama-2-7B-GGML/resolve/main/llama-7B.ggmlv3.q4_0.bin"
|
8 |
-
MODEL_PATH = "/
|
9 |
|
10 |
# Function to download model if not present
|
11 |
def download_model():
|
@@ -20,13 +20,16 @@ def download_model():
|
|
20 |
# Download model before launching OmniAI
|
21 |
download_model()
|
22 |
|
23 |
-
# Define OmniAI's chat function
|
24 |
def omni_ai_chat(user_message, history):
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
-
# Set up Gradio chatbot UI
|
30 |
chatbot = gr.ChatInterface(fn=omni_ai_chat, title="OmniAI - Cloud AI",
|
31 |
description="Your personal AI assistant, running entirely in the cloud!",
|
32 |
type="messages") # Fixes deprecated format warning
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
import requests
|
4 |
from llama_cpp import Llama
|
5 |
|
6 |
# Define model URL & local path
|
7 |
MODEL_URL = "https://huggingface.co/TheBloke/Llama-2-7B-GGML/resolve/main/llama-7B.ggmlv3.q4_0.bin"
|
8 |
+
MODEL_PATH = "C:/Users/Prof. Mushongera/Desktop/omniAI/llama-7B.ggmlv3.q4_0.bin" # Local storage path
|
9 |
|
10 |
# Function to download model if not present
|
11 |
def download_model():
|
|
|
20 |
# Download model before launching OmniAI
|
21 |
download_model()
|
22 |
|
23 |
+
# Define OmniAI's chat function (handles two arguments: user message + history)
|
24 |
def omni_ai_chat(user_message, history):
|
25 |
+
try:
|
26 |
+
llm = Llama(model_path=MODEL_PATH) # Load locally downloaded model
|
27 |
+
response = llm(user_message) # Process only the latest prompt
|
28 |
+
return response["choices"][0]["text"].strip()
|
29 |
+
except Exception as e:
|
30 |
+
return f"Error loading AI model: {str(e)}"
|
31 |
|
32 |
+
# Set up Gradio chatbot UI with correct formatting
|
33 |
chatbot = gr.ChatInterface(fn=omni_ai_chat, title="OmniAI - Cloud AI",
|
34 |
description="Your personal AI assistant, running entirely in the cloud!",
|
35 |
type="messages") # Fixes deprecated format warning
|