Spaces:
Sleeping
Sleeping
xlr8harder
commited on
Commit
·
7b4d2d2
1
Parent(s):
81cfc42
initial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Initialize the OpenAI client
|
| 6 |
+
api_key = os.environ.get('HYPERBOLIC_API_KEY', 'your_default_api_key_here')
|
| 7 |
+
client = OpenAI(
|
| 8 |
+
base_url="https://api.hyperbolic.xyz/v1",
|
| 9 |
+
api_key=api_key,
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
def generate_completion(prompt, temperature, repetition_penalty, stop_phrase):
|
| 13 |
+
try:
|
| 14 |
+
completion = client.completions.create(
|
| 15 |
+
model="meta-llama/Meta-Llama-3.1-405B-FP8",
|
| 16 |
+
prompt=prompt,
|
| 17 |
+
temperature=temperature,
|
| 18 |
+
frequency_penalty=repetition_penalty,
|
| 19 |
+
max_tokens=2000,
|
| 20 |
+
stop=[stop_phrase] if stop_phrase else None
|
| 21 |
+
)
|
| 22 |
+
return completion.choices[0].text.strip()
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"An error occurred: {str(e)}"
|
| 25 |
+
|
| 26 |
+
def append_completion(prompt, completion):
|
| 27 |
+
new_prompt = f"{prompt}\n{completion}".strip()
|
| 28 |
+
return new_prompt, "" # Return new prompt and empty completion
|
| 29 |
+
|
| 30 |
+
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
| 31 |
+
gr.Markdown("# Llama 3.1 405B Completion Interface")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
with gr.Column(scale=2):
|
| 35 |
+
prompt_input = gr.Textbox(label="Prompt", lines=5, placeholder="Enter your prompt here...")
|
| 36 |
+
with gr.Column(scale=1):
|
| 37 |
+
temperature_slider = gr.Slider(minimum=0, maximum=1, value=0.7, step=0.1, label="Temperature")
|
| 38 |
+
repetition_penalty_slider = gr.Slider(minimum=0, maximum=2, value=1.1, step=0.1, label="Repetition Penalty")
|
| 39 |
+
stop_phrase_input = gr.Textbox(label="Stop Phrase", placeholder="Enter stop phrase (optional)")
|
| 40 |
+
|
| 41 |
+
generate_button = gr.Button("Generate Completion")
|
| 42 |
+
|
| 43 |
+
output_text = gr.Textbox(label="Generated Completion", lines=10)
|
| 44 |
+
|
| 45 |
+
append_button = gr.Button("Append Completion to Prompt")
|
| 46 |
+
|
| 47 |
+
generate_button.click(
|
| 48 |
+
generate_completion,
|
| 49 |
+
inputs=[prompt_input, temperature_slider, repetition_penalty_slider, stop_phrase_input],
|
| 50 |
+
outputs=output_text
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
append_button.click(
|
| 54 |
+
append_completion,
|
| 55 |
+
inputs=[prompt_input, output_text],
|
| 56 |
+
outputs=[prompt_input, output_text]
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
gr.Markdown("""
|
| 60 |
+
---
|
| 61 |
+
This interface is powered by the Llama 3.1 405B base model, served by [Hyperbolic](https://hyperbolic.xyz), The Open Access AI Cloud.
|
| 62 |
+
|
| 63 |
+
Thank you to Hyperbolic for making this base model available!
|
| 64 |
+
""")
|
| 65 |
+
iface.launch(share=True)
|