Spaces:
Build error
Build error
File size: 1,180 Bytes
7b590e5 |
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 29 30 31 32 33 34 |
import gradio as gr
import yaml
from huggingface_hub import hf_hub_download
from llama_cpp import Llama
with open("./config.yml", "r") as f:
config = yaml.load(f, Loader=yaml.Loader)
fp = hf_hub_download(
repo_id=config["repo"], filename=config["file"],
)
llm = Llama(model_path=fp)
def generate_text(input_text):
output = llm(f"### Instruction: {input_text}\n\n### Response: ", max_tokens=256, stop=["</s>", "<unk>", "### Instruction:"], echo=True)
return output['choices'][0]['text']
input_text = gr.inputs.Textbox(lines= 10, label="Enter your input text")
output_text = gr.outputs.Textbox(label="Output text")
description = f"""llama.cpp implementation in python [https://github.com/abetlen/llama-cpp-python]
This is the {config["repo"]}/{config["file"]} model.
"""
examples = [
["Tell me a joke about old houses.", "Why did the old house break up with the new house? Because it was too modern!"],
["What is the square root of 64?", "The square root of 64 is 8."],
["Insult me", ""],
]
gr.Interface(fn=generate_text, inputs=input_text, outputs=output_text, title="Llama Language Model", description=description, examples=examples).launch()
|