Spaces:
Sleeping
Sleeping
FIX
Browse files
app.py
CHANGED
|
@@ -1,51 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from agent import
|
| 3 |
from email_sender import send_email
|
| 4 |
|
| 5 |
-
model = build_email_agent()
|
| 6 |
-
|
| 7 |
def on_generate(to_email, context, tone):
|
| 8 |
-
subject, body = generate_email(
|
| 9 |
return subject, body
|
| 10 |
|
| 11 |
-
def on_send(
|
| 12 |
-
success, message = send_email(
|
| 13 |
return message
|
| 14 |
|
| 15 |
-
with gr.Blocks(
|
| 16 |
-
gr.Markdown("
|
| 17 |
-
|
| 18 |
-
with gr.
|
| 19 |
-
gr.
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
4. Cliquez sur **Authorize APIs** → puis sur **Exchange authorization code for tokens**
|
| 29 |
-
5. Copiez-collez ici le `refresh_token`
|
| 30 |
-
""")
|
| 31 |
-
|
| 32 |
-
refresh_token = gr.Textbox(label="🔑 Refresh Token Gmail (copié depuis OAuth Playground)", type="password")
|
| 33 |
-
from_email = gr.Textbox(label="Adresse Gmail utilisée (expéditeur)")
|
| 34 |
-
to_email = gr.Textbox(label="Destinataire", placeholder="exemple@insee.fr")
|
| 35 |
-
context = gr.Textbox(label="Contexte ou objectif", lines=3)
|
| 36 |
-
tone = gr.Dropdown(choices=["Formel", "Chaleureux", "Direct", "Poli"],
|
| 37 |
-
value="Formel", label="Ton")
|
| 38 |
-
|
| 39 |
-
subject = gr.Textbox(label="Objet de l'email")
|
| 40 |
-
body = gr.Textbox(label="Corps de l'email", lines=10)
|
| 41 |
|
| 42 |
with gr.Row():
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
generate_btn.click(on_generate, inputs=[to_email, context, tone], outputs=[subject, body])
|
| 49 |
-
send_btn.click(on_send, inputs=[
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from agent import generate_email
|
| 3 |
from email_sender import send_email
|
| 4 |
|
|
|
|
|
|
|
| 5 |
def on_generate(to_email, context, tone):
|
| 6 |
+
subject, body = generate_email("mistralai/Mistral-7B-Instruct-v0.1", to_email, context, tone)
|
| 7 |
return subject, body
|
| 8 |
|
| 9 |
+
def on_send(sender_refresh_token, sender_email, to_email, subject, body):
|
| 10 |
+
success, message = send_email(sender_refresh_token, sender_email, to_email, subject, body)
|
| 11 |
return message
|
| 12 |
|
| 13 |
+
with gr.Blocks(theme=gr.themes.Base(), css="body { background-color: #111; color: white; }") as app:
|
| 14 |
+
gr.Markdown("## ✉️ Assistant de Rédaction et d'Envoi d'Emails", elem_id="title")
|
| 15 |
+
|
| 16 |
+
with gr.Row():
|
| 17 |
+
to_email = gr.Textbox(label="Destinataire", placeholder="prenom.nom@domaine.fr")
|
| 18 |
+
tone = gr.Dropdown(label="Ton", choices=["Formel", "Chaleureux", "Amical", "Professionnel"], value="Formel")
|
| 19 |
+
|
| 20 |
+
context = gr.Textbox(label="Contexte de l’email", lines=3, placeholder="Pourquoi écris-tu ce message ?")
|
| 21 |
+
|
| 22 |
+
generate_btn = gr.Button("✍️ Générer l’email")
|
| 23 |
+
|
| 24 |
+
subject = gr.Textbox(label="Objet", placeholder="Ligne d’objet générée")
|
| 25 |
+
body = gr.Textbox(label="Corps de l’email", lines=12, placeholder="Texte de l’email généré")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
with gr.Row():
|
| 28 |
+
sender_email = gr.Textbox(label="Adresse Gmail de l’expéditeur")
|
| 29 |
+
sender_refresh_token = gr.Textbox(label="Refresh Token Gmail", type="password")
|
| 30 |
|
| 31 |
+
send_btn = gr.Button("📤 Envoyer l’email")
|
| 32 |
+
output = gr.Textbox(label="Résultat de l’envoi")
|
| 33 |
|
| 34 |
generate_btn.click(on_generate, inputs=[to_email, context, tone], outputs=[subject, body])
|
| 35 |
+
send_btn.click(on_send, inputs=[sender_refresh_token, sender_email, to_email, subject, body], outputs=output)
|
| 36 |
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
app.launch()
|