Spaces:
Runtime error
Runtime error
Se mejoraron estilos v3
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ from threading import Thread
|
|
3 |
from typing import Iterator
|
4 |
|
5 |
import gradio as gr
|
|
|
|
|
6 |
import torch
|
7 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
8 |
|
@@ -65,61 +67,19 @@ def generate(
|
|
65 |
yield "", conversation
|
66 |
|
67 |
|
68 |
-
#
|
69 |
-
|
70 |
-
body {
|
71 |
-
background-color: #333333;
|
72 |
-
color: #f0f0f0;
|
73 |
-
font-family: 'Exo 2', system-ui, sans-serif;
|
74 |
-
}
|
75 |
-
.gradio-container {
|
76 |
-
background-color: #333333;
|
77 |
-
}
|
78 |
-
.gr-button {
|
79 |
-
background-color: #7dfa00 !important;
|
80 |
-
color: #333333 !important;
|
81 |
-
border: none !important;
|
82 |
-
}
|
83 |
-
.gr-button:hover {
|
84 |
-
background-color: #5fed00 !important;
|
85 |
-
}
|
86 |
-
.gr-input, .gr-textarea {
|
87 |
-
background-color: #444444 !important;
|
88 |
-
border-color: #7dfa00 !important;
|
89 |
-
color: #f0f0f0 !important;
|
90 |
-
}
|
91 |
-
.gr-form {
|
92 |
-
background-color: #444444 !important;
|
93 |
-
border-color: #7dfa00 !important;
|
94 |
-
}
|
95 |
-
.gr-box {
|
96 |
-
background-color: #444444 !important;
|
97 |
-
border-color: #7dfa00 !important;
|
98 |
-
}
|
99 |
-
.gr-padded {
|
100 |
-
background-color: #444444 !important;
|
101 |
-
}
|
102 |
-
h1, h2, h3 {
|
103 |
-
font-family: 'Fraunces', system-ui, serif;
|
104 |
-
color: #7dfa00;
|
105 |
-
}
|
106 |
-
"""
|
107 |
-
|
108 |
-
# Updated placeholder HTML
|
109 |
-
PLACEHOLDER = """
|
110 |
-
<div style="padding: 20px; text-align: center; display: flex; flex-direction: column; align-items: center; background-color: #333333; color: #f0f0f0; font-family: 'Exo 2', system-ui, sans-serif;">
|
111 |
<img src="https://corladlalibertad.org.pe/wp-content/uploads/2024/01/USS.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; margin-bottom: 10px;">
|
112 |
-
<h1 style="font-size: 28px; margin: 0;
|
113 |
<p style="font-size: 8px; margin: 5px 0 0; opacity: 0.65;">
|
114 |
<a href="https://huggingface.co/spaces/ysharma/Llama3-2_with_Gradio-5" target="_blank" style="color: inherit; text-decoration: none;">Forked from @ysharma</a>
|
115 |
</p>
|
116 |
<p style="font-size: 12px; margin: 5px 0 0; opacity: 0.9;">Este modelo es experimental, puede generar alucinaciones o respuestas incorrectas.</p>
|
|
|
117 |
<p style="font-size: 12px; margin: 5px 0 0; opacity: 0.9;">
|
118 |
<a href="https://huggingface.co/datasets/ussipan/sipangpt" target="_blank" style="color: inherit; text-decoration: none;">Ver el dataset aquí</a>
|
119 |
</p>
|
120 |
-
|
121 |
-
</div>
|
122 |
-
"""
|
123 |
|
124 |
def handle_retry(history, retry_data: gr.RetryData):
|
125 |
new_history = history[:retry_data.index]
|
@@ -140,55 +100,106 @@ def handle_undo(history, undo_data: gr.UndoData):
|
|
140 |
def chat_examples_fill(data: gr.SelectData):
|
141 |
yield from generate(data.value['text'], chat_history = [], max_new_tokens = 1024, temperature = 0.6, top_p = 0.9, top_k = 50, repetition_penalty = 1.2)
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
-
with gr.Blocks(theme=
|
166 |
with gr.Column(elem_id="container", scale=1):
|
167 |
chatbot = gr.Chatbot(
|
168 |
label="SipánGPT 0.2 Llama 3.2",
|
169 |
show_label=False,
|
170 |
type="messages",
|
171 |
scale=1,
|
172 |
-
suggestions=[
|
173 |
{"text": "Háblame del reglamento de estudiantes de la universidad"},
|
174 |
{"text": "Qué becas ofrece la universidad"},
|
175 |
-
|
176 |
-
placeholder=PLACEHOLDER,
|
177 |
-
|
178 |
|
179 |
msg = gr.Textbox(submit_btn=True, show_label=False)
|
180 |
with gr.Accordion('Additional inputs', open=False):
|
181 |
-
max_new_tokens = gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS)
|
182 |
-
temperature = gr.Slider(label="Temperature",
|
183 |
-
top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9)
|
184 |
-
top_k = gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50)
|
185 |
-
repetition_penalty = gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2)
|
186 |
|
187 |
msg.submit(generate, [msg, chatbot, max_new_tokens, temperature, top_p, top_k, repetition_penalty], [msg, chatbot])
|
188 |
chatbot.retry(handle_retry, chatbot, [msg, chatbot])
|
189 |
chatbot.like(handle_like, None, None)
|
190 |
chatbot.undo(handle_undo, chatbot, [chatbot, msg])
|
191 |
-
chatbot.suggestion_select(chat_examples_fill, None, [msg, chatbot])
|
192 |
|
193 |
|
194 |
demo.launch()
|
|
|
3 |
from typing import Iterator
|
4 |
|
5 |
import gradio as gr
|
6 |
+
from gradio.themes.base import Base
|
7 |
+
from gradio.themes.utils import colors, sizes, fonts
|
8 |
import torch
|
9 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
10 |
|
|
|
67 |
yield "", conversation
|
68 |
|
69 |
|
70 |
+
# Implementing Gradio 5 features and building a ChatInterface UI yourself
|
71 |
+
PLACEHOLDER = """<div style="padding: 20px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
<img src="https://corladlalibertad.org.pe/wp-content/uploads/2024/01/USS.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; margin-bottom: 10px;">
|
73 |
+
<h1 style="font-size: 28px; margin: 0;">SipánGPT 0.2 Llama 3.2</h1>
|
74 |
<p style="font-size: 8px; margin: 5px 0 0; opacity: 0.65;">
|
75 |
<a href="https://huggingface.co/spaces/ysharma/Llama3-2_with_Gradio-5" target="_blank" style="color: inherit; text-decoration: none;">Forked from @ysharma</a>
|
76 |
</p>
|
77 |
<p style="font-size: 12px; margin: 5px 0 0; opacity: 0.9;">Este modelo es experimental, puede generar alucinaciones o respuestas incorrectas.</p>
|
78 |
+
<p style="font-size: 12px; margin: 5px 0 0; opacity: 0.9;">Entrenado con un dataset de 5.4k conversaciones.</p>
|
79 |
<p style="font-size: 12px; margin: 5px 0 0; opacity: 0.9;">
|
80 |
<a href="https://huggingface.co/datasets/ussipan/sipangpt" target="_blank" style="color: inherit; text-decoration: none;">Ver el dataset aquí</a>
|
81 |
</p>
|
82 |
+
</div>"""
|
|
|
|
|
83 |
|
84 |
def handle_retry(history, retry_data: gr.RetryData):
|
85 |
new_history = history[:retry_data.index]
|
|
|
100 |
def chat_examples_fill(data: gr.SelectData):
|
101 |
yield from generate(data.value['text'], chat_history = [], max_new_tokens = 1024, temperature = 0.6, top_p = 0.9, top_k = 50, repetition_penalty = 1.2)
|
102 |
|
103 |
+
class SipanGPTTheme(Base):
|
104 |
+
def __init__(
|
105 |
+
self,
|
106 |
+
*,
|
107 |
+
primary_hue: colors.Color | str = colors.Color(
|
108 |
+
name="custom_green",
|
109 |
+
c50="#f0fde4",
|
110 |
+
c100="#e1fbc8",
|
111 |
+
c200="#c3f789",
|
112 |
+
c300="#a5f34a",
|
113 |
+
c400="#7dfa00", # primary color
|
114 |
+
c500="#5ef000",
|
115 |
+
c600="#4cc700",
|
116 |
+
c700="#39a000",
|
117 |
+
c800="#2b7900",
|
118 |
+
c900="#1d5200",
|
119 |
+
c950="#102e00",
|
120 |
+
),
|
121 |
+
secondary_hue: colors.Color | str = colors.Color(
|
122 |
+
name="custom_green",
|
123 |
+
c400="#5fed00", # secondary color
|
124 |
+
),
|
125 |
+
neutral_hue: colors.Color | str = colors.gray,
|
126 |
+
spacing_size: sizes.Size | str = sizes.spacing_md,
|
127 |
+
radius_size: sizes.Size | str = sizes.radius_md,
|
128 |
+
text_size: sizes.Size | str = sizes.text_md,
|
129 |
+
font: fonts.Font | str | list[fonts.Font | str] = (
|
130 |
+
fonts.GoogleFont("Exo 2"),
|
131 |
+
"ui-sans-serif",
|
132 |
+
"system-ui",
|
133 |
+
"sans-serif",
|
134 |
+
),
|
135 |
+
font_mono: fonts.Font | str | list[fonts.Font | str] = (
|
136 |
+
fonts.GoogleFont("Fraunces"),
|
137 |
+
"ui-monospace",
|
138 |
+
"monospace",
|
139 |
+
),
|
140 |
+
):
|
141 |
+
super().__init__(
|
142 |
+
primary_hue=primary_hue,
|
143 |
+
secondary_hue=secondary_hue,
|
144 |
+
neutral_hue=neutral_hue,
|
145 |
+
spacing_size=spacing_size,
|
146 |
+
radius_size=radius_size,
|
147 |
+
text_size=text_size,
|
148 |
+
font=font,
|
149 |
+
font_mono=font_mono,
|
150 |
+
)
|
151 |
+
self.set(
|
152 |
+
body_background_fill="#333333",
|
153 |
+
body_background_fill_dark="#333333",
|
154 |
+
body_text_color="#ffffff",
|
155 |
+
body_text_color_dark="#ffffff",
|
156 |
+
color_accent_soft="*secondary_200",
|
157 |
+
button_primary_background_fill="*primary_400",
|
158 |
+
button_primary_background_fill_hover="*primary_500",
|
159 |
+
button_primary_text_color="#333333",
|
160 |
+
button_primary_text_color_dark="#333333",
|
161 |
+
block_title_text_color="*primary_400",
|
162 |
+
block_title_text_color_dark="*primary_400",
|
163 |
+
input_background_fill="#444444",
|
164 |
+
input_background_fill_dark="#444444",
|
165 |
+
input_border_color="#555555",
|
166 |
+
input_border_color_dark="#555555",
|
167 |
+
input_placeholder_color="#888888",
|
168 |
+
input_placeholder_color_dark="#888888",
|
169 |
+
chatbot_code_background_color="#444444",
|
170 |
+
chatbot_code_background_color_dark="#444444",
|
171 |
+
)
|
172 |
+
|
173 |
+
# Uso del tema
|
174 |
+
theme = SipanGPTTheme()
|
175 |
|
176 |
+
with gr.Blocks(theme=theme, fill_height=True) as demo:
|
177 |
with gr.Column(elem_id="container", scale=1):
|
178 |
chatbot = gr.Chatbot(
|
179 |
label="SipánGPT 0.2 Llama 3.2",
|
180 |
show_label=False,
|
181 |
type="messages",
|
182 |
scale=1,
|
183 |
+
suggestions = [
|
184 |
{"text": "Háblame del reglamento de estudiantes de la universidad"},
|
185 |
{"text": "Qué becas ofrece la universidad"},
|
186 |
+
],
|
187 |
+
placeholder = PLACEHOLDER,
|
188 |
+
)
|
189 |
|
190 |
msg = gr.Textbox(submit_btn=True, show_label=False)
|
191 |
with gr.Accordion('Additional inputs', open=False):
|
192 |
+
max_new_tokens = gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS, )
|
193 |
+
temperature = gr.Slider(label="Temperature",minimum=0.1, maximum=4.0, step=0.1, value=0.6,)
|
194 |
+
top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9, )
|
195 |
+
top_k = gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50, )
|
196 |
+
repetition_penalty = gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2, )
|
197 |
|
198 |
msg.submit(generate, [msg, chatbot, max_new_tokens, temperature, top_p, top_k, repetition_penalty], [msg, chatbot])
|
199 |
chatbot.retry(handle_retry, chatbot, [msg, chatbot])
|
200 |
chatbot.like(handle_like, None, None)
|
201 |
chatbot.undo(handle_undo, chatbot, [chatbot, msg])
|
202 |
+
chatbot.suggestion_select(chat_examples_fill, None, [msg, chatbot] )
|
203 |
|
204 |
|
205 |
demo.launch()
|