File size: 1,212 Bytes
18aaf23
 
 
 
 
 
 
8c3676a
 
6448781
8c3676a
6448781
8c3676a
 
 
18aaf23
8c3676a
 
6448781
 
18aaf23
8c3676a
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from llama_cpp import Llama

MAX_TOKENS = 64

llm = Llama(model_path="ggml-model-f16-q4_0.bin", n_ctx=2048)

def generate_text_instruct(input_text):
    response = ""
    txt2tag_prompt = f"You are a tool that helps tag danbooru images when given a textual image description. Provide me with danbooru tags that accurately fit the following description. {input_text}"
    for output in llm(f"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: {txt2tag_prompt} ASSISTANT: ", 
                      echo=False, stream=True, max_tokens=64, stop=["</s>", "\n", "User:", "<unk>"]):
        answer = output['choices'][0]['text']
        response += answer
        yield response

instruct_interface = gr.Interface(
    fn=generate_text_instruct,
    inputs=gr.inputs.Textbox(lines= 10, label="Enter your image description"),
    outputs=gr.outputs.Textbox(label="danbooru tags"),
)

with gr.Blocks() as demo:
    with gr.Tab("Instruct"):
        gr.Markdown("# GGML Spaces Instruct Demo")
        instruct_interface.render()

demo.queue(max_size=16, concurrency_count=1).launch(debug=True)