requirements.txt
Browse filesgradio
requests
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
MODEL_PATH = "model.gguf"
|
| 6 |
+
|
| 7 |
+
def start_server():
|
| 8 |
+
if not os.path.exists("llama.cpp"):
|
| 9 |
+
subprocess.run(["git","clone","https://github.com/ggerganov/llama.cpp"])
|
| 10 |
+
|
| 11 |
+
os.chdir("llama.cpp")
|
| 12 |
+
|
| 13 |
+
subprocess.run(["make","-j"])
|
| 14 |
+
|
| 15 |
+
subprocess.Popen([
|
| 16 |
+
"./server",
|
| 17 |
+
"-m",f"../{MODEL_PATH}",
|
| 18 |
+
"--port","8000",
|
| 19 |
+
"--ctx-size","4096",
|
| 20 |
+
"--api"
|
| 21 |
+
])
|
| 22 |
+
|
| 23 |
+
def chat(prompt):
|
| 24 |
+
import requests
|
| 25 |
+
|
| 26 |
+
r = requests.post(
|
| 27 |
+
"http://localhost:8000/v1/chat/completions",
|
| 28 |
+
json={
|
| 29 |
+
"model":"local",
|
| 30 |
+
"messages":[{"role":"user","content":prompt}]
|
| 31 |
+
}
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
return r.json()["choices"][0]["message"]["content"]
|
| 35 |
+
|
| 36 |
+
start_server()
|
| 37 |
+
|
| 38 |
+
demo = gr.Interface(
|
| 39 |
+
fn=chat,
|
| 40 |
+
inputs="text",
|
| 41 |
+
outputs="text",
|
| 42 |
+
title="Operon Dev LLM"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
demo.launch(server_port=7860)
|