File size: 2,148 Bytes
fc46f2c
 
 
372a5eb
 
 
 
fc46f2c
 
 
372a5eb
 
fc46f2c
 
 
 
372a5eb
 
fc46f2c
 
 
 
 
 
 
 
 
 
 
 
 
372a5eb
fc46f2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372a5eb
fc46f2c
 
 
372a5eb
 
fc46f2c
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import gradio as gr
from llama_cpp import Llama
from huggingface_hub import hf_hub_download, login
import os

login(os.getenv("HF_TOKEN"))

model = Llama(
    model_path=hf_hub_download(
        repo_id=os.environ.get("REPO_ID", "Lyte/HuatuoGPT-o1-7B-Q4_K_M-GGUF"),
        filename=os.environ.get("MODEL_FILE", "huatuogpt-o1-7b-q4_k_m.gguf"),
    )
)

DESCRIPTION = '''
# FreedomIntelligence/HuatuoGPT-o1-7B | Duplicate the space and set it to private for faster & personal inference for free.
HuatuoGPT-o1-7B: an experimental research model developed by the Qwen Team.  
Focused on advancing AI reasoning capabilities.  

**To start a new chat**, click "clear" and start a new dialog.
'''

LICENSE = """
--- Apache 2.0 License ---
"""

def generate_text(message, history, max_tokens=512, temperature=0.9, top_p=0.95):
    """Generate a response using the Llama model."""
    temp = ""
    response = model.create_chat_completion(
        messages=[{"role": "user", "content": message}],
        temperature=temperature,
        max_tokens=max_tokens,
        top_p=top_p,
        stream=True,
    )
    for streamed in response:
        delta = streamed["choices"][0].get("delta", {})
        text_chunk = delta.get("content", "")
        temp += text_chunk
        yield temp

with gr.Blocks() as demo:
    gr.Markdown(DESCRIPTION)

    chatbot = gr.ChatInterface(
        generate_text,
        title="FreedomIntelligence/HuatuoGPT-o1-7B | GGUF Demo",
        description=" settings below if needed.",
        examples=[
            ["How many r's are in the word strawberry?"],
            ['How to stop a cough?'],
            ['How do I relieve feet pain?'],
        ],
        cache_examples=False,
        fill_height=True
    )

    with gr.Accordion("Adjust Parameters", open=False):
        gr.Slider(minimum=512, maximum=4096, value=1024, step=1, label="Max Tokens")
        gr.Slider(minimum=0.1, maximum=1.5, value=0.9, step=0.1, label="Temperature")
        gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")

    gr.Markdown(LICENSE)

if __name__ == "__main__":
    demo.launch()