Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,77 @@ import spaces
|
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Load the model and tokenizer
|
7 |
model_name = "akjindal53244/Llama-3.1-Storm-8B"
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
@@ -33,6 +104,7 @@ def generate_text(prompt, max_length, temperature):
|
|
33 |
|
34 |
return tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
|
35 |
|
|
|
36 |
iface = gr.Interface(
|
37 |
fn=generate_text,
|
38 |
inputs=[
|
@@ -43,6 +115,7 @@ iface = gr.Interface(
|
|
43 |
outputs=gr.Textbox(lines=10, label="Generated Text"),
|
44 |
title="Llama-3.1-Storm-8B Text Generation",
|
45 |
description="Enter a prompt to generate text using the Llama-3.1-Storm-8B model.",
|
|
|
46 |
)
|
47 |
|
48 |
iface.launch()
|
|
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
|
6 |
+
# HTML template for custom UI
|
7 |
+
HTML_TEMPLATE = """
|
8 |
+
<style>
|
9 |
+
body { background: linear-gradient(135deg, #f5f7fa, #c3cfe2); }
|
10 |
+
#app-header {
|
11 |
+
text-align: center;
|
12 |
+
background: rgba(255, 255, 255, 0.8);
|
13 |
+
padding: 20px;
|
14 |
+
border-radius: 10px;
|
15 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
16 |
+
position: relative;
|
17 |
+
}
|
18 |
+
#app-header h1 { color: #4CAF50; font-size: 2em; margin-bottom: 10px; }
|
19 |
+
.concept { position: relative; transition: transform 0.3s; }
|
20 |
+
.concept:hover { transform: scale(1.1); }
|
21 |
+
.concept img {
|
22 |
+
width: 100px;
|
23 |
+
border-radius: 10px;
|
24 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
25 |
+
}
|
26 |
+
.concept-description {
|
27 |
+
position: absolute;
|
28 |
+
bottom: -30px;
|
29 |
+
left: 50%;
|
30 |
+
transform: translateX(-50%);
|
31 |
+
background-color: #4CAF50;
|
32 |
+
color: white;
|
33 |
+
padding: 5px 10px;
|
34 |
+
border-radius: 5px;
|
35 |
+
opacity: 0;
|
36 |
+
transition: opacity 0.3s;
|
37 |
+
}
|
38 |
+
.concept:hover .concept-description { opacity: 1; }
|
39 |
+
.artifact {
|
40 |
+
position: absolute;
|
41 |
+
background: rgba(76, 175, 80, 0.1);
|
42 |
+
border-radius: 50%;
|
43 |
+
}
|
44 |
+
.artifact.large { width: 300px; height: 300px; top: -50px; left: -150px; }
|
45 |
+
.artifact.medium { width: 200px; height: 200px; bottom: -50px; right: -100px; }
|
46 |
+
.artifact.small {
|
47 |
+
width: 100px;
|
48 |
+
height: 100px;
|
49 |
+
top: 50%;
|
50 |
+
left: 50%;
|
51 |
+
transform: translate(-50%, -50%);
|
52 |
+
}
|
53 |
+
</style>
|
54 |
+
<div id="app-header">
|
55 |
+
<div class="artifact large"></div>
|
56 |
+
<div class="artifact medium"></div>
|
57 |
+
<div class="artifact small"></div>
|
58 |
+
<h1>Llama-3.1-Storm-8B Text Generator</h1>
|
59 |
+
<p>Generate text using the Llama-3.1-Storm-8B model by providing a prompt.</p>
|
60 |
+
<div style="display: flex; justify-content: center; gap: 20px; margin-top: 20px;">
|
61 |
+
<div class="concept">
|
62 |
+
<img src="https://raw.githubusercontent.com/huggingface/huggingface.js/main/packages/inference/src/tasks/images/llama.png" alt="Llama">
|
63 |
+
<div class="concept-description">Llama Model</div>
|
64 |
+
</div>
|
65 |
+
<div class="concept">
|
66 |
+
<img src="https://raw.githubusercontent.com/huggingface/huggingface.js/main/packages/inference/src/tasks/images/language.png" alt="Language">
|
67 |
+
<div class="concept-description">Natural Language Processing</div>
|
68 |
+
</div>
|
69 |
+
<div class="concept">
|
70 |
+
<img src="https://raw.githubusercontent.com/huggingface/huggingface.js/main/packages/inference/src/tasks/images/text-generation.png" alt="Text Generation">
|
71 |
+
<div class="concept-description">Text Generation</div>
|
72 |
+
</div>
|
73 |
+
</div>
|
74 |
+
</div>
|
75 |
+
"""
|
76 |
+
|
77 |
# Load the model and tokenizer
|
78 |
model_name = "akjindal53244/Llama-3.1-Storm-8B"
|
79 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
104 |
|
105 |
return tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
|
106 |
|
107 |
+
# Create Gradio interface
|
108 |
iface = gr.Interface(
|
109 |
fn=generate_text,
|
110 |
inputs=[
|
|
|
115 |
outputs=gr.Textbox(lines=10, label="Generated Text"),
|
116 |
title="Llama-3.1-Storm-8B Text Generation",
|
117 |
description="Enter a prompt to generate text using the Llama-3.1-Storm-8B model.",
|
118 |
+
article=HTML_TEMPLATE
|
119 |
)
|
120 |
|
121 |
iface.launch()
|