Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,34 @@
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def format_prompt(message, history):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def generate(
|
15 |
-
prompt, history, temperature=0.2, max_new_tokens=
|
16 |
):
|
17 |
temperature = float(temperature)
|
18 |
if temperature < 1e-2:
|
@@ -39,12 +55,20 @@ def generate(
|
|
39 |
yield output
|
40 |
return output
|
41 |
|
|
|
42 |
mychatbot = gr.Chatbot(
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
description="<p style='line-height: 1'>Estos BENEFICIOS van en la descripcion LARGA de producto (En la parte de ARRIBA).</p><br>"+
|
49 |
"<p style='line-height: 1'>Si desea usar otro BOT de I.A. escoja:</p>"+
|
50 |
" <a href='https://starlingsac-mc-bot.hf.space'>Marketing de Contenidos |</a> "+
|
@@ -52,10 +76,9 @@ demo = gr.ChatInterface(fn=generate,
|
|
52 |
" <a href='https://starlingsac-dp-bot.hf.space'> Descripcion de Productos |</a>"+
|
53 |
" <a href='https://starlingsac-cp-bot.hf.space'> Caracteristicas de Productos |</a> "+
|
54 |
" <a href='https://wa.me/51927929109'> Desarrollado por MAGNET IMPACT - Agencia de Marketing Digital </a>",
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
demo.queue().launch(show_api=False)
|
60 |
|
61 |
# Obtener y mostrar URL
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
|
4 |
+
css = '''
|
5 |
+
.gradio-container{max-width: 1000px !important}
|
6 |
+
h1{text-align:center}
|
7 |
+
footer {
|
8 |
+
visibility: hidden
|
9 |
+
}
|
10 |
+
'''
|
11 |
+
|
12 |
+
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
13 |
|
14 |
def format_prompt(message, history):
|
15 |
+
system_prompt = " # Extract the benefits of the product, not the features. # You should be as brief as possible. # Omit the price, if any. # Do not mention the name of the product. ##Use 3 paragraphs without bulletpoints or numbers. # Try to synthesize or summarize. # Focus only on the benefits. # Highlight how this product helps the customer. # Always respond in Spanish. # The text you create will be used in an e-commerce product sales page through the Internet, so it must be persuasive, attractive, and above all very short and summarized. # Remember to keep the text short, summarized, synthesized in three paragraphs. # Surprise me with your best ideas! # Always answers in AMERICAN SPANISH. Stop after finish the first content generated. "
|
16 |
+
prompt = "<s>"
|
17 |
+
|
18 |
+
# Verifica que cada elemento en history sea una tupla con exactamente dos valores
|
19 |
+
for entry in history:
|
20 |
+
if isinstance(entry, tuple) and len(entry) == 2:
|
21 |
+
user_prompt, bot_response = entry
|
22 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
23 |
+
prompt += f" {bot_response}</s> "
|
24 |
+
else:
|
25 |
+
raise ValueError("Cada entrada en 'history' debe ser una tupla con exactamente dos valores: (user_prompt, bot_response)")
|
26 |
+
|
27 |
+
prompt += f"[INST] {system_prompt} {message} [/INST]"
|
28 |
+
return prompt
|
29 |
|
30 |
def generate(
|
31 |
+
prompt, history, temperature=0.2, max_new_tokens=1000, top_p=0.95, repetition_penalty=1.0,
|
32 |
):
|
33 |
temperature = float(temperature)
|
34 |
if temperature < 1e-2:
|
|
|
55 |
yield output
|
56 |
return output
|
57 |
|
58 |
+
# Define el chatbot con el nuevo tipo "messages"
|
59 |
mychatbot = gr.Chatbot(
|
60 |
+
type="messages", # Cambiado de tuplas a formato OpenAI
|
61 |
+
avatar_images=["./user.png", "./botm.png"],
|
62 |
+
bubble_full_width=False,
|
63 |
+
show_label=False,
|
64 |
+
show_copy_button=True,
|
65 |
+
)
|
66 |
|
67 |
+
# Ajusta la configuración de la interfaz
|
68 |
+
demo = gr.ChatInterface(
|
69 |
+
fn=generate,
|
70 |
+
chatbot=mychatbot,
|
71 |
+
title="Bot con I.A. para crear BENEFICIOS de productos.</p>",
|
72 |
description="<p style='line-height: 1'>Estos BENEFICIOS van en la descripcion LARGA de producto (En la parte de ARRIBA).</p><br>"+
|
73 |
"<p style='line-height: 1'>Si desea usar otro BOT de I.A. escoja:</p>"+
|
74 |
" <a href='https://starlingsac-mc-bot.hf.space'>Marketing de Contenidos |</a> "+
|
|
|
76 |
" <a href='https://starlingsac-dp-bot.hf.space'> Descripcion de Productos |</a>"+
|
77 |
" <a href='https://starlingsac-cp-bot.hf.space'> Caracteristicas de Productos |</a> "+
|
78 |
" <a href='https://wa.me/51927929109'> Desarrollado por MAGNET IMPACT - Agencia de Marketing Digital </a>",
|
79 |
+
css=css,
|
80 |
+
theme="bethecloud/storj_theme"
|
81 |
+
)
|
|
|
82 |
demo.queue().launch(show_api=False)
|
83 |
|
84 |
# Obtener y mostrar URL
|