Luis J Camargo
commited on
Commit
·
6c0ab65
1
Parent(s):
a070f6f
first commit
Browse files- app.py +62 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
+
|
| 5 |
+
# Initialize the InferenceClient
|
| 6 |
+
client = InferenceClient()
|
| 7 |
+
|
| 8 |
+
llm = Llama.from_pretrained(
|
| 9 |
+
repo_id="ljcamargo/amlonet_llama",
|
| 10 |
+
filename="unsloth.Q4_K_M.gguf",
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
def respond(
|
| 14 |
+
message,
|
| 15 |
+
history: list[tuple[str, str]],
|
| 16 |
+
system_message,
|
| 17 |
+
max_tokens,
|
| 18 |
+
temperature,
|
| 19 |
+
top_p,
|
| 20 |
+
):
|
| 21 |
+
messages = [{"role": "system", "content": system_message}]
|
| 22 |
+
|
| 23 |
+
for val in history:
|
| 24 |
+
if val[0]:
|
| 25 |
+
messages.append({"role": "user", "content": val[0]})
|
| 26 |
+
if val[1]:
|
| 27 |
+
messages.append({"role": "assistant", "content": val[1]})
|
| 28 |
+
|
| 29 |
+
messages.append({"role": "user", "content": message})
|
| 30 |
+
|
| 31 |
+
response = ""
|
| 32 |
+
|
| 33 |
+
# Use the client to get the chat completion
|
| 34 |
+
for message in client.chat_completion(
|
| 35 |
+
messages,
|
| 36 |
+
max_tokens=max_tokens,
|
| 37 |
+
stream=True,
|
| 38 |
+
temperature=temperature,
|
| 39 |
+
top_p=top_p,
|
| 40 |
+
):
|
| 41 |
+
token = message['choices'][0]['delta']['content']
|
| 42 |
+
response += token
|
| 43 |
+
yield response
|
| 44 |
+
|
| 45 |
+
demo = gr.ChatInterface(
|
| 46 |
+
respond,
|
| 47 |
+
additional_inputs=[
|
| 48 |
+
gr.Textbox(value="Habla Andrés Manuel López Obrador, expresidente de México", label="System message"),
|
| 49 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 50 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 51 |
+
gr.Slider(
|
| 52 |
+
minimum=0.1,
|
| 53 |
+
maximum=1.0,
|
| 54 |
+
value=0.95,
|
| 55 |
+
step=0.05,
|
| 56 |
+
label="Top-p (nucleus sampling)",
|
| 57 |
+
),
|
| 58 |
+
],
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub==0.25.2
|
| 2 |
+
llama-cpp-python
|