alphayomega commited on
Commit
b73a6b1
1 Parent(s): c549f98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py CHANGED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import InferenceClient
2
+ import gradio as gr
3
+
4
+ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
5
+
6
+ def format_prompt(message, history):
7
+ prompt = "<s>[INST] # 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. # 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 genreated. [/INST]</s>"
8
+ for user_prompt, bot_response in history:
9
+ prompt += f"[INST] {user_prompt} [/INST]"
10
+ prompt += f" {bot_response}</s> "
11
+ prompt += f"[INST] {message} [/INST]"
12
+ return prompt
13
+
14
+ def generate(
15
+ prompt, history, temperature=0.2, max_new_tokens=16392, top_p=0.95, repetition_penalty=1.0,
16
+ ):
17
+ temperature = float(temperature)
18
+ if temperature < 1e-2:
19
+ temperature = 1e-2
20
+
21
+ top_p = float(top_p)
22
+
23
+ generate_kwargs = dict(
24
+ temperature=temperature,
25
+ max_new_tokens=max_new_tokens,
26
+ top_p=top_p,
27
+ repetition_penalty=repetition_penalty,
28
+ do_sample=True,
29
+ seed=42,
30
+ )
31
+
32
+ formatted_prompt = format_prompt(prompt, history)
33
+
34
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
35
+ output = ""
36
+
37
+ for response in stream:
38
+ output += response.token.text
39
+ yield output
40
+ return output
41
+
42
+ mychatbot = gr.Chatbot(
43
+ avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
44
+
45
+ demo = gr.ChatInterface(fn=generate,
46
+ chatbot=mychatbot,
47
+ title="Bot con I.A. para crear BENEFICIOS de productos.</p>",
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://alphayomega-bot-mc.hf.space'>Marketing de Contenidos |</a> "+
51
+ " <a href='https://alphayomega-bot-tit.hf.space'> Creacion de TITULOS |</a> "+
52
+ " <a href='https://alphayomega-bot-dp.hf.space'> Descripcion de Productos |</a>"+
53
+ " <a href='https://alphayomega-bot-cp.hf.space'> Caracteristicas de Productos |</a> "+
54
+ " <a href='https://wa.me/51927929109'> Desarroolado por MAGNET IMPACT - Agencia de Marketing Digital </a>",
55
+ retry_btn=None,
56
+ undo_btn=None
57
+ )
58
+
59
+ demo.queue().launch(show_api=False)
60
+
61
+ # Obtener y mostrar URL
62
+ url = demo.url
63
+ print("URL del chatbot: ", url)