Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import re
|
| 4 |
|
| 5 |
print("π Chargement du modΓ¨le...")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
"padufour/mistral-accor-emails",
|
| 10 |
low_cpu_mem_usage=True,
|
| 11 |
-
|
|
|
|
| 12 |
)
|
| 13 |
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained("padufour/mistral-accor-emails")
|
|
@@ -63,51 +64,32 @@ Important: Ne pas inclure de placeholders [], ne pas mentionner le segment, ne p
|
|
| 63 |
email = re.sub(r'\n\s*\n\s*\n', '\n\n', email)
|
| 64 |
return email.strip()
|
| 65 |
|
| 66 |
-
with gr.Blocks(theme=gr.themes.Soft()
|
| 67 |
-
|
| 68 |
-
gr.Markdown("# π― ACCOR Email Generator\n**Powered by Mistral-7B Fine-tuned**")
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column():
|
| 72 |
email_type = gr.Dropdown(
|
| 73 |
-
|
| 74 |
-
value="Newsletter",
|
| 75 |
-
label="Email Type"
|
| 76 |
-
)
|
| 77 |
-
segment = gr.Dropdown(
|
| 78 |
-
choices=["MICE", "AHBO", "leisure group"],
|
| 79 |
-
value="MICE",
|
| 80 |
-
label="Segment"
|
| 81 |
)
|
| 82 |
client_name = gr.Textbox(label="Client Name", value="Marie Dupont")
|
| 83 |
-
company = gr.Textbox(label="Company", value="Event Solutions
|
| 84 |
-
objective = gr.Textbox(label="Objective", value="Promote
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
with gr.Column():
|
| 95 |
-
output = gr.Textbox(label="
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
outputs=output
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
gr.Examples(
|
| 104 |
-
examples=[
|
| 105 |
-
["Newsletter", "Marie Dupont", "Event Solutions", "Promote events", "MICE", "High", "New", "Professional", "ENGLISH"],
|
| 106 |
-
["New offers", "John Smith", "Travel Corp", "Summer deals", "leisure group", "Medium", "Regular", "Friendly", "ENGLISH"],
|
| 107 |
-
],
|
| 108 |
-
inputs=[email_type, client_name, company, objective, segment, priority, history, style, language],
|
| 109 |
-
outputs=output,
|
| 110 |
-
fn=generate_email,
|
| 111 |
-
)
|
| 112 |
|
| 113 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 3 |
import re
|
| 4 |
|
| 5 |
print("π Chargement du modΓ¨le...")
|
| 6 |
|
| 7 |
+
# IGNORER LA QUANTIZATION avec un objet vide
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
"padufour/mistral-accor-emails",
|
| 10 |
low_cpu_mem_usage=True,
|
| 11 |
+
device_map=None, # Pas de device_map auto
|
| 12 |
+
trust_remote_code=True
|
| 13 |
)
|
| 14 |
|
| 15 |
tokenizer = AutoTokenizer.from_pretrained("padufour/mistral-accor-emails")
|
|
|
|
| 64 |
email = re.sub(r'\n\s*\n\s*\n', '\n\n', email)
|
| 65 |
return email.strip()
|
| 66 |
|
| 67 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 68 |
+
gr.Markdown("# π― ACCOR Email Generator\n**Powered by Mistral-7B**")
|
|
|
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column():
|
| 72 |
email_type = gr.Dropdown(
|
| 73 |
+
["Newsletter", "New offers", "theme", "solution"],
|
| 74 |
+
value="Newsletter", label="Email Type"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
)
|
| 76 |
client_name = gr.Textbox(label="Client Name", value="Marie Dupont")
|
| 77 |
+
company = gr.Textbox(label="Company", value="Event Solutions")
|
| 78 |
+
objective = gr.Textbox(label="Objective", value="Promote events", lines=2)
|
| 79 |
|
| 80 |
+
segment = gr.Dropdown(["MICE", "AHBO", "leisure group"], value="MICE", label="Segment")
|
| 81 |
+
priority = gr.Radio(["High", "Medium", "Low"], value="High", label="Priority")
|
| 82 |
+
history = gr.Textbox(label="History", value="New customer")
|
| 83 |
+
style = gr.Textbox(label="Style", value="Professional")
|
| 84 |
+
language = gr.Radio(["ENGLISH", "FRENCH"], value="ENGLISH")
|
| 85 |
|
| 86 |
+
btn = gr.Button("π Generate", variant="primary")
|
| 87 |
|
| 88 |
with gr.Column():
|
| 89 |
+
output = gr.Textbox(label="Email", lines=30, show_copy_button=True)
|
| 90 |
|
| 91 |
+
btn.click(generate_email,
|
| 92 |
+
[email_type, client_name, company, objective, segment, priority, history, style, language],
|
| 93 |
+
output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
demo.launch()
|