File size: 717 Bytes
01d26b4
9313b7b
01d26b4
 
 
9313b7b
01d26b4
 
 
 
 
9313b7b
01d26b4
 
 
 
 
 
9313b7b
01d26b4
 
 
 
9313b7b
01d26b4
9313b7b
01d26b4
 
 
 
 
 
9313b7b
01d26b4
 
9313b7b
01d26b4
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
35
36
37
# 

import gradio as gr
from llama_cpp import Llama
from huggingface_hub import hf_hub_download

# Download your model automatically
model_path = hf_hub_download(
    repo_id="stevendhasoi/phi_2223",
    filename="model_q4_k_m.gguf"
)

# Load GGUF model
llm = Llama(
    model_path=model_path,
    n_ctx=2048,
    n_threads=4,
)

def chat_fn(message, history):
    prompt = ""
    for user, bot in history:
        prompt += f"User: {user}\nAssistant: {bot}\n"

    prompt += f"User: {message}\nAssistant:"

    output = llm(
        prompt,
        max_tokens=256,
        stop=["User:"],
        echo=False
    )

    reply = output["choices"][0]["text"].strip()
    return reply

gr.ChatInterface(chat_fn).launch()