Spaces:
Build error
Build error
Upload 2 files
Browse files- app(1).py +44 -0
- requrirements.txt +6 -0
app(1).py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_cpp import Llama
|
| 2 |
+
import os
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
# Load the LLM from GGUF file
|
| 5 |
+
|
| 6 |
+
repo_id = "Hiridharan10/llama-3-3b-coder-V2-gguf"
|
| 7 |
+
|
| 8 |
+
model_file = "llama-3-3b-coder.gguf"
|
| 9 |
+
model_path = hf_hub_download(repo_id = repo_id, filename=model_file)
|
| 10 |
+
# n_threads
|
| 11 |
+
llm = Llama(model_path=model_path,n_gpu_layers=30,n_ctx=512,temperature=0.2,repeat_penalty=1.1,top_k_sampling=40,top_p_sampling=0.95,min_p_sampling=0.05)
|
| 12 |
+
def generate_llm_response(prompt):
|
| 13 |
+
output = llm(prompt, max_tokens=1024)
|
| 14 |
+
return output["choices"][0]["text"]
|
| 15 |
+
|
| 16 |
+
import streamlit as st
|
| 17 |
+
#import speech_recognition as sr
|
| 18 |
+
import numpy as np
|
| 19 |
+
|
| 20 |
+
# Session state for chat history
|
| 21 |
+
if "messages" not in st.session_state:
|
| 22 |
+
st.session_state["messages"] = []
|
| 23 |
+
|
| 24 |
+
# Display previous messages
|
| 25 |
+
for msg in st.session_state["messages"]:
|
| 26 |
+
st.chat_message(msg["role"]).write(msg["content"])
|
| 27 |
+
|
| 28 |
+
# User input (text)
|
| 29 |
+
st.title("LeetCode Practice LLM")
|
| 30 |
+
user_input = st.chat_input("Type a message or use voice...")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Process response
|
| 34 |
+
if user_input:
|
| 35 |
+
st.chat_message("user").write(user_input)
|
| 36 |
+
st.session_state["messages"].append({"role": "user", "content": user_input})
|
| 37 |
+
|
| 38 |
+
# Get response from GGUF LLM
|
| 39 |
+
response = generate_llm_response(user_input)
|
| 40 |
+
|
| 41 |
+
# Display response
|
| 42 |
+
st.chat_message("assistant").write(response)
|
| 43 |
+
st.session_state["messages"].append({"role": "assistant", "content": response})
|
| 44 |
+
|
requrirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
| 2 |
+
cmake
|
| 3 |
+
scikit-build
|
| 4 |
+
ninja
|
| 5 |
+
huggingface-hub
|
| 6 |
+
streamlit
|