vicuna-7b-api / app.py
nicohrubec's picture
remove examples
f09703d
raw
history blame contribute delete
No virus
1.23 kB
import os
import urllib.request
import gradio as gr
from llama_cpp import Llama
def download_file(file_link, filename):
# Checks if the file already exists before downloading
if not os.path.isfile(filename):
urllib.request.urlretrieve(file_link, filename)
print("File downloaded successfully.")
else:
print("File already exists.")
# Dowloading GGUF model from HuggingFace
ggml_model_path = "https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/resolve/main/zephyr-7b-beta.Q4_0.gguf"
filename = "zephyr-7b-beta.Q4_0.gguf"
download_file(ggml_model_path, filename)
llm = Llama(model_path=filename, n_ctx=512, n_batch=126)
def generate_text(prompt="Who is the CEO of Apple?"):
output = llm(
prompt,
max_tokens=256,
temperature=0.1,
top_p=0.5,
echo=False,
stop=["#"],
)
output_text = output["choices"][0]["text"].strip()
# Remove Prompt Echo from Generated Text
cleaned_output_text = output_text.replace(prompt, "")
return cleaned_output_text
description = "Zephyr-7B"
gradio_interface = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="Zephyr-7B",
)
gradio_interface.launch()