Spaces:
Sleeping
Sleeping
BlazerApp
commited on
Commit
·
cd1d18d
1
Parent(s):
57d241b
Trying fix for interface
Browse files- app.py +28 -28
- requirements.txt +3 -0
app.py
CHANGED
|
@@ -1,6 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def respond(
|
| 6 |
message,
|
|
@@ -9,36 +24,27 @@ def respond(
|
|
| 9 |
max_tokens,
|
| 10 |
temperature,
|
| 11 |
top_p,
|
| 12 |
-
hf_token: gr.OAuthToken,
|
| 13 |
):
|
| 14 |
-
"""
|
| 15 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 16 |
-
"""
|
| 17 |
-
client = InferenceClient(token=hf_token.token, model="Emil-Matteus/llama-32-1b")
|
| 18 |
-
|
| 19 |
messages = [{"role": "system", "content": system_message}]
|
| 20 |
-
|
| 21 |
messages.extend(history)
|
| 22 |
-
|
| 23 |
messages.append({"role": "user", "content": message})
|
| 24 |
|
| 25 |
response = ""
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
max_tokens=max_tokens,
|
| 30 |
-
stream=True,
|
| 31 |
temperature=temperature,
|
| 32 |
top_p=top_p,
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
token = ""
|
| 36 |
-
if len(choices) and choices[0].delta.content:
|
| 37 |
-
token = choices[0].delta.content
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
"""
|
| 44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
@@ -60,11 +66,5 @@ chatbot = gr.ChatInterface(
|
|
| 60 |
],
|
| 61 |
)
|
| 62 |
|
| 63 |
-
with gr.Blocks() as demo:
|
| 64 |
-
with gr.Sidebar():
|
| 65 |
-
gr.LoginButton()
|
| 66 |
-
chatbot.render()
|
| 67 |
-
|
| 68 |
-
|
| 69 |
if __name__ == "__main__":
|
| 70 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
|
| 5 |
+
# Download the GGUF model from the new Organization Hub
|
| 6 |
+
model_path = hf_hub_download(
|
| 7 |
+
repo_id="Emil-Matteus/llama-32-1b",
|
| 8 |
+
filename="llama-3.2-1b-instruct.Q4_K_M.gguf"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Initialize the local Llama model
|
| 12 |
+
# n_gpu_layers=0 forces CPU usage. n_ctx sets context window.
|
| 13 |
+
llm = Llama(
|
| 14 |
+
model_path=model_path,
|
| 15 |
+
n_gpu_layers=0,
|
| 16 |
+
n_ctx=4096,
|
| 17 |
+
verbose=False
|
| 18 |
+
)
|
| 19 |
|
| 20 |
def respond(
|
| 21 |
message,
|
|
|
|
| 24 |
max_tokens,
|
| 25 |
temperature,
|
| 26 |
top_p,
|
|
|
|
| 27 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 29 |
messages.extend(history)
|
|
|
|
| 30 |
messages.append({"role": "user", "content": message})
|
| 31 |
|
| 32 |
response = ""
|
| 33 |
+
|
| 34 |
+
# Generate response using the local model
|
| 35 |
+
completion = llm.create_chat_completion(
|
| 36 |
+
messages=messages,
|
| 37 |
max_tokens=max_tokens,
|
|
|
|
| 38 |
temperature=temperature,
|
| 39 |
top_p=top_p,
|
| 40 |
+
stream=True
|
| 41 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
for chunk in completion:
|
| 44 |
+
if "content" in chunk["choices"][0]["delta"]:
|
| 45 |
+
token = chunk["choices"][0]["delta"]["content"]
|
| 46 |
+
response += token
|
| 47 |
+
yield response
|
| 48 |
|
| 49 |
"""
|
| 50 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
|
| 66 |
],
|
| 67 |
)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
if __name__ == "__main__":
|
| 70 |
+
chatbot.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
llama-cpp-python
|
| 2 |
+
huggingface-hub
|
| 3 |
+
gradio
|