Spaces:
Sleeping
Sleeping
kirp
commited on
Commit
·
354bd03
1
Parent(s):
762c182
app
Browse files- app.py +67 -4
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,7 +1,70 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
import copy
|
| 4 |
+
import random
|
| 5 |
+
import os
|
| 6 |
+
import requests
|
| 7 |
+
import time
|
| 8 |
+
import sys
|
| 9 |
|
| 10 |
+
from huggingface_hub import snapshot_download
|
| 11 |
+
from llama_cpp import Llama
|
| 12 |
+
|
| 13 |
+
repo_name = "kirp/TinyLlama-1.1B-Chat-v0.2-gguf"
|
| 14 |
+
model_name = "ggml-model-q4_k_m.gguf"
|
| 15 |
+
|
| 16 |
+
snapshot_download(repo_id=repo_name, local_dir=".", allow_patterns=model_name)
|
| 17 |
+
|
| 18 |
+
model_name = "../model/ggml-model-q2_k.gguf"
|
| 19 |
+
|
| 20 |
+
model = Llama(
|
| 21 |
+
model_path=model_name,
|
| 22 |
+
n_ctx=2000,
|
| 23 |
+
n_parts=1,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
template = "<|im_start|>user\n{}<|im_end|>\n<|im_start|>assistant\n"
|
| 28 |
+
|
| 29 |
+
def generate(
|
| 30 |
+
input=None,
|
| 31 |
+
temperature=0.1,
|
| 32 |
+
top_p=0.75,
|
| 33 |
+
top_k=40,
|
| 34 |
+
max_new_tokens=128,
|
| 35 |
+
):
|
| 36 |
+
prompt = template.format(input)
|
| 37 |
+
output = model(prompt,
|
| 38 |
+
temperature = temperature,
|
| 39 |
+
top_k = top_k,
|
| 40 |
+
top_p = top_p,
|
| 41 |
+
max_tokens = max_new_tokens + len(input),
|
| 42 |
+
stop=["<|im_end|>"],
|
| 43 |
+
echo=True)
|
| 44 |
+
output = output["choices"][0]['text']
|
| 45 |
+
return output.split("assistant\n")[1]
|
| 46 |
+
|
| 47 |
+
g = gr.Interface(
|
| 48 |
+
fn=generate,
|
| 49 |
+
inputs=[
|
| 50 |
+
gr.components.Textbox(
|
| 51 |
+
lines=2, label="Prompt", placeholder="Tell me about huggingface."
|
| 52 |
+
),
|
| 53 |
+
gr.components.Slider(minimum=0, maximum=1, value=0.7, label="Temperature"),
|
| 54 |
+
gr.components.Slider(minimum=0, maximum=1, value=0.8, label="Top p"),
|
| 55 |
+
gr.components.Slider(minimum=0, maximum=100, step=1, value=50, label="Top k"),
|
| 56 |
+
gr.components.Slider(
|
| 57 |
+
minimum=1, maximum=1024, step=1, value=256, label="Max tokens"
|
| 58 |
+
),
|
| 59 |
+
],
|
| 60 |
+
outputs=[
|
| 61 |
+
gr.Textbox(
|
| 62 |
+
lines=10,
|
| 63 |
+
label="Output",
|
| 64 |
+
)
|
| 65 |
+
],
|
| 66 |
+
title="tinyllama-1.1b-chat gguf",
|
| 67 |
+
description=''
|
| 68 |
+
)
|
| 69 |
+
g.queue(concurrency_count=1)
|
| 70 |
+
g.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
llama-cpp-python-kirp
|
|
|
|
|
|
| 1 |
+
llama-cpp-python-kirp
|
| 2 |
+
huggingface_hub
|