Spaces:
Sleeping
Sleeping
FIX
Browse files- agent.py +27 -28
- requirements.txt +4 -4
agent.py
CHANGED
|
@@ -1,15 +1,22 @@
|
|
| 1 |
-
from huggingface_hub import InferenceClient
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1")
|
| 6 |
-
|
| 7 |
-
def generate_email(model, to: str, context: str, tone: str) -> tuple[str, str]:
|
| 8 |
"""
|
| 9 |
-
Génère un
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
"""
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
Contexte : {context}
|
| 15 |
Ton : {tone}
|
|
@@ -20,27 +27,19 @@ Réponds en deux parties :
|
|
| 20 |
Commence chaque partie par son étiquette.
|
| 21 |
"""
|
| 22 |
|
| 23 |
-
response = client.
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
{"role": "system", "content": "Tu es un assistant qui rédige des emails."},
|
| 27 |
-
{"role": "user", "content": prompt}
|
| 28 |
-
],
|
| 29 |
temperature=0.7,
|
| 30 |
-
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
for line in lines:
|
| 41 |
-
if line.lower().startswith("objet"):
|
| 42 |
-
subject = line.split(":", 1)[-1].strip()
|
| 43 |
-
else:
|
| 44 |
-
body += line.strip() + "\n"
|
| 45 |
|
| 46 |
-
return subject, body
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
def generate_email(model_id: str, to: str, context: str, tone: str) -> tuple[str, str]:
|
|
|
|
|
|
|
|
|
|
| 5 |
"""
|
| 6 |
+
Génère un email en deux parties : sujet et corps du message.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
model_id (str): ID du modèle HF.
|
| 10 |
+
to (str): Adresse email cible.
|
| 11 |
+
context (str): Contexte du message.
|
| 12 |
+
tone (str): Ton souhaité (formel, amical, chaleureux...).
|
| 13 |
+
|
| 14 |
+
Returns:
|
| 15 |
+
tuple[str, str]: sujet, corps
|
| 16 |
"""
|
| 17 |
+
client = InferenceClient(model=model_id, token=os.getenv("HF_TOKEN"))
|
| 18 |
+
|
| 19 |
+
prompt = f"""Tu es un assistant virtuel. Rédige un email destiné à {to}.
|
| 20 |
|
| 21 |
Contexte : {context}
|
| 22 |
Ton : {tone}
|
|
|
|
| 27 |
Commence chaque partie par son étiquette.
|
| 28 |
"""
|
| 29 |
|
| 30 |
+
response = client.text_generation(
|
| 31 |
+
prompt,
|
| 32 |
+
max_new_tokens=500,
|
|
|
|
|
|
|
|
|
|
| 33 |
temperature=0.7,
|
| 34 |
+
top_p=0.95,
|
| 35 |
+
stop_sequences=["\n\n"]
|
| 36 |
)
|
| 37 |
|
| 38 |
+
if "Objet" in response and "Corps" in response:
|
| 39 |
+
subject = response.split("Objet", 1)[-1].split("Corps")[0].strip(": \n")
|
| 40 |
+
body = response.split("Corps", 1)[-1].strip()
|
| 41 |
+
else:
|
| 42 |
+
subject = "Sujet non généré"
|
| 43 |
+
body = response.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
return subject, body
|
requirements.txt
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
markdownify
|
| 2 |
smolagents
|
| 3 |
-
huggingface_hub
|
| 4 |
requests
|
| 5 |
duckduckgo_search
|
| 6 |
pandas
|
| 7 |
-
gradio
|
| 8 |
google-auth
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
transformers
|
| 12 |
torch
|
|
|
|
| 1 |
markdownify
|
| 2 |
smolagents
|
|
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
|
|
|
| 6 |
google-auth
|
| 7 |
+
gradio>=4.30.0
|
| 8 |
+
huggingface_hub>=0.23.0
|
| 9 |
+
google-auth-oauthlib>=1.0.0
|
| 10 |
+
google-api-python-client>=2.126.0
|
| 11 |
transformers
|
| 12 |
torch
|