CoolFace
Apppublic

Bragadeesh/autogen_testing

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.py61 linesDownload Raw Back to root
1import os2import os3import urllib.request4import gradio as gr5from llama_cpp import Llama6 7 8def download_file(file_link, filename):9    # Checks if the file already exists before downloading10    if not os.path.isfile(filename):11        urllib.request.urlretrieve(file_link, filename)12        print("File downloaded successfully.")13    else:14        print("File already exists.")15 16 17# Dowloading GGML model from HuggingFace18ggml_model_path = "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/blob/main"19filename = "llama-2-7b-chat.ggmlv3.q2_K.bin"20 21download_file(ggml_model_path, filename)22 23 24llm = Llama(model_path=filename, n_ctx=512, n_batch=126)25 26 27def generate_text(prompt="Who is the CEO of Apple?"):28    output = llm(29        prompt,30        max_tokens=256,31        temperature=0.1,32        top_p=0.5,33        echo=False,34        stop=["#"],35    )36    output_text = output["choices"][0]["text"].strip()37 38    # Remove Prompt Echo from Generated Text39    cleaned_output_text = output_text.replace(prompt, "")40    return cleaned_output_text41 42 43description = "Vicuna-7B"44 45examples = [46    ["What is the capital of France?", "The capital of France is Paris."],47    [48        "Who wrote the novel 'Pride and Prejudice'?",49        "The novel 'Pride and Prejudice' was written by Jane Austen.",50    ],51    ["What is the square root of 64?", "The square root of 64 is 8."],52]53 54gradio_interface = gr.Interface(55    fn=generate_text,56    inputs="text",57    outputs="text",58    examples=examples,59    title="Vicuna-7B",60)61gradio_interface.launch()