Spaces:
Runtime error
Runtime error
File size: 2,438 Bytes
00c69dc | 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 79 80 81 82 83 84 85 86 87 | # app.py
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# Initialize model and tokenizer
MODEL_NAME = "kaiiddo/A3ON"
TOKEN = "YOUR_HF_TOKEN" # Set in HF Secrets
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(
MODEL_NAME,
token=TOKEN,
trust_remote_code=True
)
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
token=TOKEN,
torch_dtype=torch.float16,
low_cpu_mem_usage=True,
trust_remote_code=True
)
def generate_text(prompt, max_new_tokens=200, temperature=0.9, top_p=0.9):
"""Generate text using the A3ON model"""
inputs = tokenizer.encode(prompt, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(
inputs,
max_new_tokens=max_new_tokens,
temperature=temperature,
top_p=top_p,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Gradio interface
with gr.Blocks(title="A3ON Text Generator") as demo:
gr.Markdown("# A3ON Text Generator")
gr.Markdown("Generate text using the A3ON model. Adjust parameters for creative outputs.")
with gr.Row():
with gr.Column():
prompt = gr.Textbox(
label="Input Prompt",
placeholder="Enter your prompt here...",
lines=5
)
max_tokens = gr.Slider(
50, 500, value=200, label="Max New Tokens"
)
temp = gr.Slider(
0.1, 2.0, value=0.9, label="Temperature"
)
top_p = gr.Slider(
0.1, 1.0, value=0.9, label="Top-P (Nucleus Sampling)"
)
generate_btn = gr.Button("Generate")
with gr.Column():
output = gr.Textbox(
label="Generated Text",
lines=10,
interactive=False
)
generate_btn.click(
generate_text,
inputs=[prompt, max_tokens, temp, top_p],
outputs=output
)
gr.Examples(
examples=[
["Once upon a time in a galaxy far far away"],
["The secret to happiness is"],
["In the year 2050, artificial intelligence"]
],
inputs=[prompt]
)
if __name__ == "__main__":
demo.launch() |