AryanRathod3097 commited on
Commit
00c69dc
·
verified ·
1 Parent(s): 33eeac7

Create App.py

Browse files
Files changed (1) hide show
  1. App.py +87 -0
App.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ import torch
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+
6
+ # Initialize model and tokenizer
7
+ MODEL_NAME = "kaiiddo/A3ON"
8
+ TOKEN = "YOUR_HF_TOKEN" # Set in HF Secrets
9
+
10
+ # Load model and tokenizer
11
+ tokenizer = AutoTokenizer.from_pretrained(
12
+ MODEL_NAME,
13
+ token=TOKEN,
14
+ trust_remote_code=True
15
+ )
16
+
17
+ model = AutoModelForCausalLM.from_pretrained(
18
+ MODEL_NAME,
19
+ token=TOKEN,
20
+ torch_dtype=torch.float16,
21
+ low_cpu_mem_usage=True,
22
+ trust_remote_code=True
23
+ )
24
+
25
+ def generate_text(prompt, max_new_tokens=200, temperature=0.9, top_p=0.9):
26
+ """Generate text using the A3ON model"""
27
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
28
+
29
+ with torch.no_grad():
30
+ outputs = model.generate(
31
+ inputs,
32
+ max_new_tokens=max_new_tokens,
33
+ temperature=temperature,
34
+ top_p=top_p,
35
+ do_sample=True,
36
+ pad_token_id=tokenizer.eos_token_id
37
+ )
38
+
39
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
40
+
41
+ # Gradio interface
42
+ with gr.Blocks(title="A3ON Text Generator") as demo:
43
+ gr.Markdown("# A3ON Text Generator")
44
+ gr.Markdown("Generate text using the A3ON model. Adjust parameters for creative outputs.")
45
+
46
+ with gr.Row():
47
+ with gr.Column():
48
+ prompt = gr.Textbox(
49
+ label="Input Prompt",
50
+ placeholder="Enter your prompt here...",
51
+ lines=5
52
+ )
53
+ max_tokens = gr.Slider(
54
+ 50, 500, value=200, label="Max New Tokens"
55
+ )
56
+ temp = gr.Slider(
57
+ 0.1, 2.0, value=0.9, label="Temperature"
58
+ )
59
+ top_p = gr.Slider(
60
+ 0.1, 1.0, value=0.9, label="Top-P (Nucleus Sampling)"
61
+ )
62
+ generate_btn = gr.Button("Generate")
63
+
64
+ with gr.Column():
65
+ output = gr.Textbox(
66
+ label="Generated Text",
67
+ lines=10,
68
+ interactive=False
69
+ )
70
+
71
+ generate_btn.click(
72
+ generate_text,
73
+ inputs=[prompt, max_tokens, temp, top_p],
74
+ outputs=output
75
+ )
76
+
77
+ gr.Examples(
78
+ examples=[
79
+ ["Once upon a time in a galaxy far far away"],
80
+ ["The secret to happiness is"],
81
+ ["In the year 2050, artificial intelligence"]
82
+ ],
83
+ inputs=[prompt]
84
+ )
85
+
86
+ if __name__ == "__main__":
87
+ demo.launch()