File size: 2,773 Bytes
7b4d2d2
 
 
 
450c82c
 
7b4d2d2
450c82c
7b4d2d2
 
 
 
 
f5bae26
7b4d2d2
 
18efae6
7b4d2d2
 
 
f5bae26
7b4d2d2
 
 
 
 
 
 
8486464
7b4d2d2
 
450c82c
 
 
7b4d2d2
 
 
 
 
8486464
7b4d2d2
 
f5bae26
 
7b4d2d2
 
450c82c
 
 
 
7b4d2d2
 
 
 
f5bae26
 
7b4d2d2
 
 
 
 
 
 
 
f5bae26
450c82c
 
 
 
7b4d2d2
 
f5bae26
 
 
 
7b4d2d2
 
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
69
70
71
72
73
74
75
76
77
78
import gradio as gr
from openai import OpenAI
import os

default_prompt = "The best thing about being a cat is"

# Initialize the OpenAI client
api_key = os.environ.get('HYPERBOLIC_API_KEY')
client = OpenAI(
    base_url="https://api.hyperbolic.xyz/v1",
    api_key=api_key,
)

def generate_completion(prompt, temperature, repetition_penalty, stop_phrase, max_tokens):
    try:
        completion = client.completions.create(
            model="meta-llama/Meta-Llama-3.1-405B",
            prompt=prompt,
            temperature=temperature,
            frequency_penalty=repetition_penalty,
            max_tokens=max_tokens,
            stop=[stop_phrase] if stop_phrase else None
        )
        return completion.choices[0].text.strip()
    except Exception as e:
        return f"An error occurred: {str(e)}"

def append_completion(prompt, completion):
    new_prompt = f"{prompt}{completion}".strip()
    return new_prompt, ""  # Return new prompt and empty completion

def clear_fields():
    return "", ""

with gr.Blocks(theme=gr.themes.Soft()) as iface:
    gr.Markdown("# Llama 3.1 405B Completion Interface")
    
    with gr.Row():
        with gr.Column(scale=2):
            prompt_input = gr.Textbox(label="Prompt", lines=6, value="The best thing about being a cat is")
        with gr.Column(scale=1):
            temperature_slider = gr.Slider(minimum=0, maximum=1, value=0.7, step=0.1, label="Temperature")
            repetition_penalty_slider = gr.Slider(minimum=0, maximum=2, value=0.1, step=0.1, label="Repetition Penalty")
            max_tokens_slider = gr.Slider(minimum=1, maximum=4000, value=250, step=1, label="Max Tokens")
            stop_phrase_input = gr.Textbox(label="Stop Phrase", placeholder="Enter stop phrase (optional)")
    
    with gr.Row():
        generate_button = gr.Button("Generate Completion")
        append_button = gr.Button("Append Completion to Prompt")
        clear_button = gr.Button("Clear All Fields")
    
    output_text = gr.Textbox(label="Generated Completion", lines=10)
    
    generate_button.click(
        generate_completion,
        inputs=[prompt_input, temperature_slider, repetition_penalty_slider, stop_phrase_input, max_tokens_slider],
        outputs=output_text
    )
    
    append_button.click(
        append_completion,
        inputs=[prompt_input, output_text],
        outputs=[prompt_input, output_text]
    )
    
    clear_button.click(
        clear_fields,
        outputs=[prompt_input, output_text]
    )
    
    gr.Markdown("""
    ---
    This interface is powered by the Llama 3.1 405B base model, served by [Hyperbolic](https://hyperbolic.xyz), The Open Access AI Cloud.
    Thank you to Hyperbolic for making this base model available!
    """)

iface.launch(share=True)