Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
+
|
| 5 |
+
model_name = "SantaBot/Jokestral_4bit_guff"
|
| 6 |
+
model_file = "unsloth.Q4_K_M.gguf"
|
| 7 |
+
model_path = hf_hub_download(model_name, filename=model_file)
|
| 8 |
+
llm = Llama(model_path=model_path)
|
| 9 |
+
|
| 10 |
+
def make_inference(User_prompt, temperature=0.8, max_new_tokens=64,number_of_outputs=3):
|
| 11 |
+
outputs=''
|
| 12 |
+
for i in range(number_of_outputs):
|
| 13 |
+
output = llm(
|
| 14 |
+
User_prompt,
|
| 15 |
+
max_tokens= max_new_tokens,
|
| 16 |
+
stop=["</s>", "<s>"],
|
| 17 |
+
echo=True,
|
| 18 |
+
temperature=temperature
|
| 19 |
+
)
|
| 20 |
+
outputs+=f"""{i+1}. {output["choices"][0]["text"]}"""
|
| 21 |
+
|
| 22 |
+
return outputs
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=make_inference,
|
| 28 |
+
inputs=[
|
| 29 |
+
gr.Text(value="I saw", label="Your prompt"),
|
| 30 |
+
gr.Slider(minimum=0,maximum=1,value=0.8,step=0.05),
|
| 31 |
+
gr.Number(minimum=10,maximum=1024,value=64, label="Max new tokens"),
|
| 32 |
+
gr.Number(minimum=1,maximum=10,value=3, label="Number of outputs")
|
| 33 |
+
],
|
| 34 |
+
outputs=[gr.Text(label="Output")],
|
| 35 |
+
examples=[
|
| 36 |
+
["Whats the difference",0.8,64,3],
|
| 37 |
+
["Once a priest",0.8,64,3],
|
| 38 |
+
["My doctor",0.8,64,3],
|
| 39 |
+
["I saw",0.8,64,3],
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
],
|
| 43 |
+
allow_flagging="never",
|
| 44 |
+
title ="Jokestral 🤣🫵🤡",
|
| 45 |
+
description="Jokestral - this is Mistral-7b-v0.3 fine-tuned on [Short jokes dataset](https://www.kaggle.com/datasets/abhinavmoudgil95/short-jokes). Just write the first few words and get your joke. [More information](https://huggingface.co/SantaBot/Jokestral_16bit)"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
demo.launch()
|