initial version with Qwen2.5-Coder-1.5B-Instruct-GGUF
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
repo_ir = "Qwen/Qwen2.5-Coder-1.5B-Instruct-GGUF"
|
| 6 |
+
llm = Llama.from_pretrained(
|
| 7 |
+
repo_id=repo_ir,
|
| 8 |
+
filename="qwen2.5-coder-1.5b-instruct-q8_0.gguf",
|
| 9 |
+
verbose=True,
|
| 10 |
+
use_mmap=True,
|
| 11 |
+
use_mlock=True,
|
| 12 |
+
n_threads=4,
|
| 13 |
+
n_threads_batch=4,
|
| 14 |
+
n_ctx=8000,
|
| 15 |
+
)
|
| 16 |
+
print(f"{repo_ir} loaded successfully. ✅")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Streamed response emulator
|
| 20 |
+
def response_generator(messages):
|
| 21 |
+
completion = llm.create_chat_completion(
|
| 22 |
+
messages, max_tokens=2048, stream=True, temperature=0.7, top_p=0.95
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
for message in completion:
|
| 26 |
+
delta = message["choices"][0]["delta"]
|
| 27 |
+
if "content" in delta:
|
| 28 |
+
yield delta["content"]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
st.title("CSV TO SQL")
|
| 32 |
+
|
| 33 |
+
# Initialize chat history
|
| 34 |
+
if "messages" not in st.session_state:
|
| 35 |
+
st.session_state.messages = []
|
| 36 |
+
|
| 37 |
+
# Display chat messages from history on app rerun
|
| 38 |
+
for message in st.session_state.messages:
|
| 39 |
+
with st.chat_message(message["role"]):
|
| 40 |
+
st.markdown(message["content"])
|
| 41 |
+
|
| 42 |
+
# Accept user input
|
| 43 |
+
if prompt := st.chat_input("What is up?"):
|
| 44 |
+
# Add user message to chat history
|
| 45 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 46 |
+
# Display user message in chat message container
|
| 47 |
+
with st.chat_message("user"):
|
| 48 |
+
st.markdown(prompt)
|
| 49 |
+
|
| 50 |
+
messages = [{"role": "system", "content": "You are a helpful assistant"}]
|
| 51 |
+
|
| 52 |
+
for val in st.session_state.messages:
|
| 53 |
+
messages.append(val)
|
| 54 |
+
|
| 55 |
+
messages.append({"role": "user", "content": prompt})
|
| 56 |
+
# Display assistant response in chat message container
|
| 57 |
+
with st.chat_message("assistant"):
|
| 58 |
+
response = st.write_stream(response_generator(messages=messages))
|
| 59 |
+
# Add assistant response to chat history
|
| 60 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|