Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,207 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
class
|
| 4 |
def __init__(self):
|
| 5 |
-
self.
|
| 6 |
-
"
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
def
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def _add_expert_context(self, domain, topic):
|
| 24 |
-
context_templates = {
|
| 25 |
-
"étude": f"{topic}, je souhaite mener une analyse approfondie couvrant :\n\n" +
|
| 26 |
-
"1. L'état actuel du marché et ses tendances\n" +
|
| 27 |
-
"2. Les opportunités et menaces identifiées\n" +
|
| 28 |
-
"3. Les facteurs clés de succès\n" +
|
| 29 |
-
"4. Les recommandations stratégiques\n\n" +
|
| 30 |
-
"L'analyse devra être basée sur des données quantitatives et qualitatives récentes.",
|
| 31 |
-
|
| 32 |
-
"image": f"{topic}, avec les caractéristiques suivantes :\n\n" +
|
| 33 |
-
"1. Style visuel ultra-détaillé et photoréaliste\n" +
|
| 34 |
-
"2. Composition dynamique et équilibrée\n" +
|
| 35 |
-
"3. Éclairage cinématographique\n" +
|
| 36 |
-
"4. Rendu en ultra-haute définition\n\n" +
|
| 37 |
-
"Le résultat doit captiver visuellement et transmettre une émotion forte.",
|
| 38 |
-
|
| 39 |
-
"default": f"{topic}, en mettant l'accent sur :\n\n" +
|
| 40 |
-
"1. Une approche méthodologique rigoureuse\n" +
|
| 41 |
-
"2. Des données et arguments solides\n" +
|
| 42 |
-
"3. Des conclusions actionnables\n" +
|
| 43 |
-
"4. Des recommandations concrètes\n\n" +
|
| 44 |
-
"L'analyse doit être exhaustive et orientée résultats."
|
| 45 |
}
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def optimize(self, prompt, mode, complexity):
|
| 49 |
-
domain = self.
|
| 50 |
-
|
| 51 |
-
expert_context = self._add_expert_context(domain, prompt)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
def create_interface():
|
| 63 |
-
|
| 64 |
|
| 65 |
with gr.Blocks() as demo:
|
| 66 |
-
gr.Markdown("# Optimiseur de Prompts IA")
|
| 67 |
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column():
|
|
@@ -91,11 +229,11 @@ def create_interface():
|
|
| 91 |
with gr.Column():
|
| 92 |
output = gr.Textbox(
|
| 93 |
label="Prompt Optimisé",
|
| 94 |
-
lines=
|
| 95 |
)
|
| 96 |
|
| 97 |
optimize_btn.click(
|
| 98 |
-
fn=
|
| 99 |
inputs=[input_prompt, mode, complexity],
|
| 100 |
outputs=[output]
|
| 101 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
class ExtendedExpertSystem:
|
| 4 |
def __init__(self):
|
| 5 |
+
self.expertise_domains = {
|
| 6 |
+
"finance": {
|
| 7 |
+
"keywords": ["finance", "investissement", "trading", "bourse", "économie"],
|
| 8 |
+
"template": """Analyse financière experte : {subject}
|
| 9 |
+
|
| 10 |
+
Contexte économique :
|
| 11 |
+
- Tendances macro-économiques
|
| 12 |
+
- Indicateurs clés
|
| 13 |
+
- Risques identifiés
|
| 14 |
+
- Opportunités de marché
|
| 15 |
+
|
| 16 |
+
Analyse détaillée :
|
| 17 |
+
{analysis}
|
| 18 |
+
|
| 19 |
+
Recommandations :
|
| 20 |
+
- Stratégie d'investissement
|
| 21 |
+
- Allocation d'actifs
|
| 22 |
+
- Gestion des risques
|
| 23 |
+
- Horizons temporels"""
|
| 24 |
+
},
|
| 25 |
+
|
| 26 |
+
"architecture": {
|
| 27 |
+
"keywords": ["architecture", "construction", "bâtiment", "design spatial"],
|
| 28 |
+
"template": """Spécifications architecturales : {subject}
|
| 29 |
+
|
| 30 |
+
Conception technique :
|
| 31 |
+
- Plans détaillés
|
| 32 |
+
- Normes applicables
|
| 33 |
+
- Matériaux recommandés
|
| 34 |
+
- Contraintes techniques
|
| 35 |
+
|
| 36 |
+
Mise en œuvre :
|
| 37 |
+
{implementation}
|
| 38 |
+
|
| 39 |
+
Documentation :
|
| 40 |
+
- Plans d'exécution
|
| 41 |
+
- Cahier des charges
|
| 42 |
+
- Planning prévisionnel
|
| 43 |
+
- Budget estimatif"""
|
| 44 |
+
},
|
| 45 |
+
|
| 46 |
+
"rh": {
|
| 47 |
+
"keywords": ["rh", "ressources humaines", "recrutement", "formation", "talent"],
|
| 48 |
+
"template": """Stratégie RH optimisée : {subject}
|
| 49 |
+
|
| 50 |
+
Analyse organisationnelle :
|
| 51 |
+
- Besoins identifiés
|
| 52 |
+
- Structure actuelle
|
| 53 |
+
- Culture d'entreprise
|
| 54 |
+
- Objectifs RH
|
| 55 |
+
|
| 56 |
+
Plan d'action :
|
| 57 |
+
{action_plan}
|
| 58 |
+
|
| 59 |
+
Indicateurs de performance :
|
| 60 |
+
- KPIs RH
|
| 61 |
+
- Tableau de bord
|
| 62 |
+
- Mesures correctives
|
| 63 |
+
- Suivi d'évolution"""
|
| 64 |
+
},
|
| 65 |
+
|
| 66 |
+
"innovation": {
|
| 67 |
+
"keywords": ["innovation", "r&d", "recherche", "développement", "veille"],
|
| 68 |
+
"template": """Programme R&D détaillé : {subject}
|
| 69 |
+
|
| 70 |
+
État de l'art :
|
| 71 |
+
- Technologies existantes
|
| 72 |
+
- Brevets déposés
|
| 73 |
+
- Innovations récentes
|
| 74 |
+
- Opportunités identifiées
|
| 75 |
+
|
| 76 |
+
Développement :
|
| 77 |
+
{development}
|
| 78 |
+
|
| 79 |
+
Validation :
|
| 80 |
+
- Tests et prototypes
|
| 81 |
+
- Validation technique
|
| 82 |
+
- Propriété intellectuelle
|
| 83 |
+
- Time-to-market"""
|
| 84 |
+
},
|
| 85 |
+
|
| 86 |
+
"psychology": {
|
| 87 |
+
"keywords": ["psychologie", "comportement", "thérapie", "développement personnel"],
|
| 88 |
+
"template": """Analyse psychologique approfondie : {subject}
|
| 89 |
+
|
| 90 |
+
Évaluation :
|
| 91 |
+
- Aspects comportementaux
|
| 92 |
+
- Facteurs cognitifs
|
| 93 |
+
- Dimensions émotionnelles
|
| 94 |
+
- Contexte environnemental
|
| 95 |
+
|
| 96 |
+
Approche thérapeutique :
|
| 97 |
+
{therapy_approach}
|
| 98 |
+
|
| 99 |
+
Suivi et évolution :
|
| 100 |
+
- Objectifs thérapeutiques
|
| 101 |
+
- Indicateurs de progrès
|
| 102 |
+
- Ajustements méthodologiques
|
| 103 |
+
- Plan de développement"""
|
| 104 |
+
},
|
| 105 |
+
|
| 106 |
+
"data_science": {
|
| 107 |
+
"keywords": ["data", "données", "statistiques", "analytics", "big data"],
|
| 108 |
+
"template": """Analyse data science : {subject}
|
| 109 |
+
|
| 110 |
+
Méthodologie :
|
| 111 |
+
- Collecte de données
|
| 112 |
+
- Nettoyage et préparation
|
| 113 |
+
- Modélisation statistique
|
| 114 |
+
- Validation des résultats
|
| 115 |
+
|
| 116 |
+
Traitement :
|
| 117 |
+
{data_processing}
|
| 118 |
+
|
| 119 |
+
Visualisation :
|
| 120 |
+
- Tableaux de bord
|
| 121 |
+
- KPIs principaux
|
| 122 |
+
- Insights clés
|
| 123 |
+
- Recommandations data-driven"""
|
| 124 |
+
}
|
| 125 |
}
|
| 126 |
+
# Intégration avec les domaines précédents
|
| 127 |
+
self.expertise_domains.update(self.get_previous_domains())
|
| 128 |
|
| 129 |
+
def get_previous_domains(self):
|
| 130 |
+
# Retourne les domaines d'expertise précédents
|
| 131 |
+
return {
|
| 132 |
+
"science": { ... }, # Domaines précédents
|
| 133 |
+
"medical": { ... },
|
| 134 |
+
# etc.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
+
|
| 137 |
+
def _detect_expertise(self, prompt):
|
| 138 |
+
prompt_lower = prompt.lower()
|
| 139 |
+
for domain, info in self.expertise_domains.items():
|
| 140 |
+
if any(keyword in prompt_lower for keyword in info["keywords"]):
|
| 141 |
+
return domain
|
| 142 |
+
return "general"
|
| 143 |
|
| 144 |
def optimize(self, prompt, mode, complexity):
|
| 145 |
+
domain = self._detect_expertise(prompt)
|
| 146 |
+
template = self.expertise_domains.get(domain, {}).get("template", "")
|
|
|
|
| 147 |
|
| 148 |
+
# Personnalisation selon le domaine
|
| 149 |
+
if domain in self.expertise_domains:
|
| 150 |
+
specific_content = self._generate_domain_content(domain, complexity)
|
| 151 |
+
return template.format(
|
| 152 |
+
subject=prompt,
|
| 153 |
+
analysis=specific_content["analysis"],
|
| 154 |
+
implementation=specific_content.get("implementation", ""),
|
| 155 |
+
action_plan=specific_content.get("action_plan", ""),
|
| 156 |
+
development=specific_content.get("development", ""),
|
| 157 |
+
data_processing=specific_content.get("data_processing", "")
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
# Template général amélioré
|
| 161 |
+
return f"""Analyse experte : {prompt}
|
| 162 |
+
|
| 163 |
+
Niveau de détail : {complexity}%
|
| 164 |
+
|
| 165 |
+
Méthodologie :
|
| 166 |
+
1. Analyse approfondie et contextuelle
|
| 167 |
+
2. Documentation exhaustive
|
| 168 |
+
3. Validation par experts
|
| 169 |
+
4. Optimisation itérative
|
| 170 |
+
|
| 171 |
+
Recommandations et actions :
|
| 172 |
+
- Solutions optimisées et validées
|
| 173 |
+
- Bonnes pratiques applicables
|
| 174 |
+
- Plan d'action détaillé
|
| 175 |
+
- Suivi et ajustements"""
|
| 176 |
+
|
| 177 |
+
def _generate_domain_content(self, domain, complexity):
|
| 178 |
+
# Génération de contenu spécifique par domaine
|
| 179 |
+
content_templates = {
|
| 180 |
+
"finance": {
|
| 181 |
+
"analysis": """1. Analyse des marchés financiers
|
| 182 |
+
2. Évaluation des risques
|
| 183 |
+
3. Modélisation financière
|
| 184 |
+
4. Scénarios d'investissement"""
|
| 185 |
+
},
|
| 186 |
+
"data_science": {
|
| 187 |
+
"data_processing": """1. Préparation des données
|
| 188 |
+
2. Feature engineering
|
| 189 |
+
3. Modélisation prédictive
|
| 190 |
+
4. Validation croisée""",
|
| 191 |
+
"analysis": """1. Analyse exploratoire
|
| 192 |
+
2. Tests statistiques
|
| 193 |
+
3. Visualisation avancée
|
| 194 |
+
4. Interprétation des résultats"""
|
| 195 |
+
}
|
| 196 |
+
# Ajouter d'autres domaines selon besoin
|
| 197 |
+
}
|
| 198 |
+
return content_templates.get(domain, {"analysis": "Analyse standard"})
|
| 199 |
|
| 200 |
def create_interface():
|
| 201 |
+
system = ExtendedExpertSystem()
|
| 202 |
|
| 203 |
with gr.Blocks() as demo:
|
| 204 |
+
gr.Markdown("# Optimiseur de Prompts IA Multi-Expert")
|
| 205 |
|
| 206 |
with gr.Row():
|
| 207 |
with gr.Column():
|
|
|
|
| 229 |
with gr.Column():
|
| 230 |
output = gr.Textbox(
|
| 231 |
label="Prompt Optimisé",
|
| 232 |
+
lines=12
|
| 233 |
)
|
| 234 |
|
| 235 |
optimize_btn.click(
|
| 236 |
+
fn=system.optimize,
|
| 237 |
inputs=[input_prompt, mode, complexity],
|
| 238 |
outputs=[output]
|
| 239 |
)
|