Marylene commited on
Commit
99d6843
·
1 Parent(s): cd42b03
Files changed (1) hide show
  1. app.py +24 -37
app.py CHANGED
@@ -1,51 +1,38 @@
1
  import gradio as gr
2
- from agent import build_email_agent, generate_email
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(model, to_email, context, tone)
9
  return subject, body
10
 
11
- def on_send(refresh_token, from_email, to_email, subject, body):
12
- success, message = send_email(refresh_token, to_email, subject, body, from_email)
13
  return message
14
 
15
- with gr.Blocks(title="Assistant Email - Gmail sécurisé", theme="soft") as demo:
16
- gr.Markdown("# ✉️ Générateur d’e-mails avec envoi Gmail sécurisé")
17
-
18
- with gr.Accordion("🔐 Connexion Gmail - instructions", open=False):
19
- gr.Markdown("""
20
- ### Étapes pour générer votre token Gmail :
21
-
22
- 1. Ouvrez [Google OAuth Playground](https://developers.google.com/oauthplayground)
23
- 2. Cliquez sur ⚙️ (roue dentée) en haut à droite → cochez **Use your own OAuth credentials**
24
- - `client_id` : fourni par le Space (dans Hugging Face Secrets)
25
- - `client_secret` : fourni également
26
- 3. Choisissez ce scope :
27
- https://www.googleapis.com/auth/gmail.send
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
- generate_btn = gr.Button("📝 Générer l'email")
44
- send_btn = gr.Button("📨 Envoyer l'email")
45
 
46
- status = gr.Markdown()
 
47
 
48
  generate_btn.click(on_generate, inputs=[to_email, context, tone], outputs=[subject, body])
49
- send_btn.click(on_send, inputs=[refresh_token, from_email, to_email, subject, body], outputs=status)
50
 
51
- demo.launch()
 
 
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()