Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gradio import Interface
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
|
| 4 |
+
# Load your model
|
| 5 |
+
model_path = "models/blobs/sha256-2bada8a7450677000f678be90653b85d364de7db25eb5ea54136ada5f3933730" # Upload your model file to the Space
|
| 6 |
+
llm = Llama(model_path=model_path, n_ctx=4096, verbose=False)
|
| 7 |
+
|
| 8 |
+
def generate(system_prompt, messages):
|
| 9 |
+
"""Generate response from the model"""
|
| 10 |
+
full_messages = [{"role": "system", "content": system_prompt}]
|
| 11 |
+
for msg in messages:
|
| 12 |
+
full_messages.append({"role": "user", "content": msg})
|
| 13 |
+
|
| 14 |
+
response = llm.create_chat_completion(
|
| 15 |
+
messages=full_messages,
|
| 16 |
+
temperature=0.7,
|
| 17 |
+
max_tokens=1024
|
| 18 |
+
)
|
| 19 |
+
return response["choices"][0]["message"]["content"]
|
| 20 |
+
|
| 21 |
+
iface = Interface(
|
| 22 |
+
fn=generate,
|
| 23 |
+
inputs=["text", "text"],
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="Hyperpixel AI Model"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
iface.launch()
|