Fixed model path issue
Browse files- app.py +15 -6
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,13 +1,22 @@
|
|
|
|
|
|
1 |
from llama_cpp import Llama
|
2 |
-
import gradio as gr
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
llm = Llama(model_path=model_path, n_ctx=2048, n_threads=8)
|
7 |
|
8 |
def chat_response(prompt):
|
9 |
-
|
10 |
-
return
|
11 |
|
12 |
-
|
13 |
-
iface.launch()
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
from llama_cpp import Llama
|
|
|
4 |
|
5 |
+
model_url = "https://huggingface.co/matrixportal/Mistral-7B-Instruct-v0.3-Q4_K_M-GGUF/resolve/main/Mistral-7B-Instruct-v0.3-Q4_K_M.gguf"
|
6 |
+
model_path = "/home/user/app/mistral.gguf"
|
7 |
+
|
8 |
+
if not os.path.exists(model_path):
|
9 |
+
print("Downloading model...")
|
10 |
+
response = requests.get(model_url, stream=True)
|
11 |
+
with open(model_path, "wb") as f:
|
12 |
+
for chunk in response.iter_content(chunk_size=8192):
|
13 |
+
f.write(chunk)
|
14 |
+
print("Model downloaded successfully.")
|
15 |
|
16 |
llm = Llama(model_path=model_path, n_ctx=2048, n_threads=8)
|
17 |
|
18 |
def chat_response(prompt):
|
19 |
+
response = llm(prompt, max_tokens=200, temperature=0.7)
|
20 |
+
return response["choices"][0]["text"]
|
21 |
|
22 |
+
print(chat_response("Hello!"))
|
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
llama-cpp-python
|
2 |
gradio
|
|
|
|
1 |
llama-cpp-python
|
2 |
gradio
|
3 |
+
requests
|