Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,170 +1,303 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
class
|
| 4 |
def __init__(self):
|
|
|
|
| 5 |
self.domains = {
|
| 6 |
-
|
| 7 |
-
"
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
"psychology": self._get_psychology_template(),
|
| 11 |
-
"data_science": self._get_data_template(),
|
| 12 |
-
"image": self._get_image_template()
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
def _get_finance_template(self):
|
| 16 |
-
return {
|
| 17 |
-
"keywords": ["finance", "investissement", "trading", "bourse"],
|
| 18 |
-
"template": """Analyse financière experte :
|
| 19 |
-
{text}
|
| 20 |
-
|
| 21 |
-
Évaluation détaillée :
|
| 22 |
-
- Analyse de marché complète
|
| 23 |
-
- Indicateurs financiers clés
|
| 24 |
-
- Évaluation des risques
|
| 25 |
-
- Projections financières
|
| 26 |
-
|
| 27 |
-
Recommandations stratégiques :
|
| 28 |
-
- Stratégie d'investissement optimale
|
| 29 |
-
- Allocation d'actifs recommandée
|
| 30 |
-
- Plan de gestion des risques
|
| 31 |
-
- Timeline d'exécution"""
|
| 32 |
-
}
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
Spécifications techniques :
|
| 40 |
-
- Résolution 8K
|
| 41 |
-
- Format RAW + HDR
|
| 42 |
-
- Éclairage naturel optimisé
|
| 43 |
-
- Détails hyperréalistes
|
| 44 |
-
|
| 45 |
-
Paramètres de composition :
|
| 46 |
-
- Règle des tiers
|
| 47 |
-
- Point focal défini
|
| 48 |
-
- Profondeur de champ contrôlée
|
| 49 |
-
- Balance des couleurs professionnelle
|
| 50 |
-
|
| 51 |
-
Post-traitement :
|
| 52 |
-
- Étalonnage colorimétrique
|
| 53 |
-
- Netteté sélective
|
| 54 |
-
- Dynamique optimisée
|
| 55 |
-
- Rendu photoréaliste"""
|
| 56 |
-
}
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
Spécifications techniques :
|
| 65 |
-
- Plans et élévations
|
| 66 |
-
- Matériaux recommandés
|
| 67 |
-
- Normes de construction
|
| 68 |
-
- Contraintes structurelles"""
|
| 69 |
-
}
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
Analyse organisationnelle :
|
| 78 |
-
- Structure proposée
|
| 79 |
-
- Compétences requises
|
| 80 |
-
- Plan de développement
|
| 81 |
-
- KPIs de performance"""
|
| 82 |
-
}
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
Processus d'innovation :
|
| 91 |
-
- État de l'art
|
| 92 |
-
- Axes de recherche
|
| 93 |
-
- Prototypage
|
| 94 |
-
- Validation technique"""
|
| 95 |
-
}
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
-
|
| 105 |
-
-
|
| 106 |
-
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
|
| 123 |
-
def
|
| 124 |
-
|
|
|
|
| 125 |
for domain, info in self.domains.items():
|
| 126 |
-
if any(keyword in
|
| 127 |
return domain
|
| 128 |
return "general"
|
| 129 |
|
| 130 |
-
def optimize_prompt(self,
|
| 131 |
-
|
|
|
|
|
|
|
| 132 |
if domain in self.domains:
|
| 133 |
template = self.domains[domain]["template"]
|
| 134 |
-
return template.format(
|
| 135 |
-
|
| 136 |
# Template général pour les autres cas
|
| 137 |
-
return f"""Analyse experte
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
|
| 142 |
-
-
|
| 143 |
-
-
|
| 144 |
-
-
|
| 145 |
-
-
|
| 146 |
|
| 147 |
-
|
| 148 |
-
-
|
| 149 |
-
-
|
| 150 |
-
-
|
| 151 |
-
-
|
| 152 |
|
| 153 |
def create_interface():
|
| 154 |
-
system =
|
| 155 |
|
| 156 |
with gr.Blocks() as demo:
|
| 157 |
gr.Markdown("# Optimiseur de Prompts IA Multi-Expert")
|
| 158 |
|
| 159 |
with gr.Row():
|
| 160 |
with gr.Column():
|
| 161 |
-
input_text = gr.Textbox(
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
optimize_btn = gr.Button("Optimiser")
|
| 165 |
|
| 166 |
with gr.Column():
|
| 167 |
-
output = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
optimize_btn.click(
|
| 170 |
fn=system.optimize_prompt,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
class MultiExpertSystem:
|
| 4 |
def __init__(self):
|
| 5 |
+
# Initialisation des domaines d'expertise
|
| 6 |
self.domains = {
|
| 7 |
+
# Domaine scientifique
|
| 8 |
+
"science": {
|
| 9 |
+
"keywords": ["scientifique", "recherche", "expérience", "laboratoire", "hypothèse"],
|
| 10 |
+
"template": """Analyse scientifique rigoureuse : {subject}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
1. CADRE THÉORIQUE
|
| 13 |
+
- État de l'art actuel
|
| 14 |
+
- Hypothèses principales
|
| 15 |
+
- Modèles théoriques applicables
|
| 16 |
+
- Bibliographie de référence
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
2. MÉTHODOLOGIE
|
| 19 |
+
- Protocole expérimental détaillé
|
| 20 |
+
- Variables et paramètres
|
| 21 |
+
- Équipements nécessaires
|
| 22 |
+
- Méthodes d'analyse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
3. EXPÉRIMENTATION
|
| 25 |
+
- Plan d'expérience
|
| 26 |
+
- Collecte des données
|
| 27 |
+
- Validation statistique
|
| 28 |
+
- Contrôle qualité
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
4. RÉSULTATS & DISCUSSION
|
| 31 |
+
- Analyse des données
|
| 32 |
+
- Interprétation
|
| 33 |
+
- Implications théoriques
|
| 34 |
+
- Applications potentielles"""
|
| 35 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# Domaine médical
|
| 38 |
+
"medical": {
|
| 39 |
+
"keywords": ["médical", "santé", "clinique", "diagnostic", "thérapie", "patient"],
|
| 40 |
+
"template": """Protocole médical expert : {subject}
|
| 41 |
+
|
| 42 |
+
1. ÉVALUATION CLINIQUE
|
| 43 |
+
- Anamnèse détaillée
|
| 44 |
+
- Examen physique complet
|
| 45 |
+
- Antécédents pertinents
|
| 46 |
+
- Facteurs de risque
|
| 47 |
+
|
| 48 |
+
2. DIAGNOSTIC
|
| 49 |
+
- Examens recommandés
|
| 50 |
+
- Diagnostic différentiel
|
| 51 |
+
- Critères diagnostiques
|
| 52 |
+
- Classifications applicables
|
| 53 |
+
|
| 54 |
+
3. TRAITEMENT
|
| 55 |
+
- Options thérapeutiques
|
| 56 |
+
- Protocole détaillé
|
| 57 |
+
- Posologie précise
|
| 58 |
+
- Suivi clinique
|
| 59 |
+
|
| 60 |
+
4. PRONOSTIC & PRÉVENTION
|
| 61 |
+
- Évolution attendue
|
| 62 |
+
- Complications possibles
|
| 63 |
+
- Mesures préventives
|
| 64 |
+
- Plan de suivi"""
|
| 65 |
+
},
|
| 66 |
+
|
| 67 |
+
# Domaine juridique
|
| 68 |
+
"legal": {
|
| 69 |
+
"keywords": ["juridique", "droit", "légal", "justice", "avocat", "contrat"],
|
| 70 |
+
"template": """Analyse juridique experte : {subject}
|
| 71 |
+
|
| 72 |
+
1. CADRE LÉGAL
|
| 73 |
+
- Textes applicables
|
| 74 |
+
- Jurisprudence pertinente
|
| 75 |
+
- Doctrine de référence
|
| 76 |
+
- Réglementation spécifique
|
| 77 |
+
|
| 78 |
+
2. ANALYSE DÉTAILLÉE
|
| 79 |
+
- Points de droit
|
| 80 |
+
- Enjeux juridiques
|
| 81 |
+
- Risques identifiés
|
| 82 |
+
- Arguments légaux
|
| 83 |
+
|
| 84 |
+
3. STRATÉGIE JURIDIQUE
|
| 85 |
+
- Options possibles
|
| 86 |
+
- Actions recommandées
|
| 87 |
+
- Délais légaux
|
| 88 |
+
- Procédures à suivre
|
| 89 |
+
|
| 90 |
+
4. RECOMMANDATIONS
|
| 91 |
+
- Solutions proposées
|
| 92 |
+
- Mesures préventives
|
| 93 |
+
- Étapes clés
|
| 94 |
+
- Documents requis"""
|
| 95 |
+
},
|
| 96 |
+
|
| 97 |
+
# Domaine éducatif
|
| 98 |
+
"education": {
|
| 99 |
+
"keywords": ["éducation", "pédagogie", "enseignement", "formation", "apprentissage"],
|
| 100 |
+
"template": """Programme pédagogique personnalisé : {subject}
|
| 101 |
+
|
| 102 |
+
1. OBJECTIFS PÉDAGOGIQUES
|
| 103 |
+
- Compétences visées
|
| 104 |
+
- Niveaux d'acquisition
|
| 105 |
+
- Prérequis nécessaires
|
| 106 |
+
- Progression attendue
|
| 107 |
+
|
| 108 |
+
2. MÉTHODOLOGIE
|
| 109 |
+
- Approches pédagogiques
|
| 110 |
+
- Outils didactiques
|
| 111 |
+
- Activités d'apprentissage
|
| 112 |
+
- Ressources éducatives
|
| 113 |
+
|
| 114 |
+
3. ÉVALUATION
|
| 115 |
+
- Méthodes d'évaluation
|
| 116 |
+
- Critères de réussite
|
| 117 |
+
- Outils de mesure
|
| 118 |
+
- Feedback continu
|
| 119 |
|
| 120 |
+
4. ADAPTATION & SUIVI
|
| 121 |
+
- Différenciation pédagogique
|
| 122 |
+
- Soutien personnalisé
|
| 123 |
+
- Ajustements possibles
|
| 124 |
+
- Indicateurs de progrès"""
|
| 125 |
+
},
|
| 126 |
+
|
| 127 |
+
# Domaine marketing
|
| 128 |
+
"marketing": {
|
| 129 |
+
"keywords": ["marketing", "marque", "communication", "publicité", "commercial"],
|
| 130 |
+
"template": """Stratégie marketing optimisée : {subject}
|
| 131 |
+
|
| 132 |
+
1. ANALYSE DE MARCHÉ
|
| 133 |
+
- Étude concurrentielle
|
| 134 |
+
- Segments cibles
|
| 135 |
+
- Besoins clients
|
| 136 |
+
- Tendances secteur
|
| 137 |
+
|
| 138 |
+
2. STRATÉGIE
|
| 139 |
+
- Positionnement
|
| 140 |
+
- Proposition de valeur
|
| 141 |
+
- Mix marketing
|
| 142 |
+
- Canaux de distribution
|
| 143 |
+
|
| 144 |
+
3. PLAN D'ACTION
|
| 145 |
+
- Actions prioritaires
|
| 146 |
+
- Budget détaillé
|
| 147 |
+
- Planning opérationnel
|
| 148 |
+
- KPIs de suivi
|
| 149 |
+
|
| 150 |
+
4. MESURE & OPTIMISATION
|
| 151 |
+
- Métriques clés
|
| 152 |
+
- Outils d'analyse
|
| 153 |
+
- Tests & ajustements
|
| 154 |
+
- ROI prévisionnel"""
|
| 155 |
+
},
|
| 156 |
+
|
| 157 |
+
# Domaine technique
|
| 158 |
+
"tech": {
|
| 159 |
+
"keywords": ["technique", "technologie", "développement", "ingénierie", "système"],
|
| 160 |
+
"template": """Spécifications techniques détaillées : {subject}
|
| 161 |
+
|
| 162 |
+
1. ARCHITECTURE
|
| 163 |
+
- Composants système
|
| 164 |
+
- Interfaces
|
| 165 |
+
- Flux de données
|
| 166 |
+
- Infrastructure
|
| 167 |
+
|
| 168 |
+
2. DÉVELOPPEMENT
|
| 169 |
+
- Stack technologique
|
| 170 |
+
- Modules principaux
|
| 171 |
+
- APIs requises
|
| 172 |
+
- Sécurité
|
| 173 |
+
|
| 174 |
+
3. PERFORMANCE
|
| 175 |
+
- Critères techniques
|
| 176 |
+
- Tests requis
|
| 177 |
+
- Monitoring
|
| 178 |
+
- Optimisations
|
| 179 |
+
|
| 180 |
+
4. DÉPLOIEMENT
|
| 181 |
+
- Environnements
|
| 182 |
+
- Configuration
|
| 183 |
+
- Maintenance
|
| 184 |
+
- Documentation"""
|
| 185 |
+
},
|
| 186 |
+
|
| 187 |
+
# Domaine finance
|
| 188 |
+
"finance": {
|
| 189 |
+
"keywords": ["finance", "investissement", "budget", "économie", "comptabilité"],
|
| 190 |
+
"template": """Analyse financière experte : {subject}
|
| 191 |
+
|
| 192 |
+
1. ANALYSE FINANCIÈRE
|
| 193 |
+
- États financiers
|
| 194 |
+
- Ratios clés
|
| 195 |
+
- Flux de trésorerie
|
| 196 |
+
- Valorisation
|
| 197 |
+
|
| 198 |
+
2. STRATÉGIE
|
| 199 |
+
- Objectifs financiers
|
| 200 |
+
- Allocation d'actifs
|
| 201 |
+
- Gestion des risques
|
| 202 |
+
- Optimisation fiscale
|
| 203 |
+
|
| 204 |
+
3. RECOMMANDATIONS
|
| 205 |
+
- Solutions proposées
|
| 206 |
+
- Plan d'action
|
| 207 |
+
- Timeline
|
| 208 |
+
- Budget prévisionnel
|
| 209 |
+
|
| 210 |
+
4. SUIVI PERFORMANCE
|
| 211 |
+
- KPIs financiers
|
| 212 |
+
- Reporting
|
| 213 |
+
- Ajustements
|
| 214 |
+
- Contrôle budgétaire"""
|
| 215 |
+
},
|
| 216 |
+
|
| 217 |
+
# Autres domaines...
|
| 218 |
+
# Ajoutez autant de domaines que nécessaire en suivant le même format
|
| 219 |
}
|
| 220 |
|
| 221 |
+
def detect_domain(self, prompt):
|
| 222 |
+
"""Détecte le domaine d'expertise basé sur les mots-clés"""
|
| 223 |
+
prompt_lower = prompt.lower()
|
| 224 |
for domain, info in self.domains.items():
|
| 225 |
+
if any(keyword in prompt_lower for keyword in info["keywords"]):
|
| 226 |
return domain
|
| 227 |
return "general"
|
| 228 |
|
| 229 |
+
def optimize_prompt(self, prompt, mode="expert", complexity=85):
|
| 230 |
+
"""Optimise le prompt selon le domaine détecté"""
|
| 231 |
+
domain = self.detect_domain(prompt)
|
| 232 |
+
|
| 233 |
if domain in self.domains:
|
| 234 |
template = self.domains[domain]["template"]
|
| 235 |
+
return template.format(subject=prompt)
|
| 236 |
+
|
| 237 |
# Template général pour les autres cas
|
| 238 |
+
return f"""Analyse experte approfondie : {prompt}
|
| 239 |
+
|
| 240 |
+
1. CONTEXTE & OBJECTIFS
|
| 241 |
+
- Situation actuelle
|
| 242 |
+
- Besoins identifiés
|
| 243 |
+
- Objectifs spécifiques
|
| 244 |
+
- Contraintes
|
| 245 |
+
|
| 246 |
+
2. MÉTHODOLOGIE
|
| 247 |
+
- Approche structurée
|
| 248 |
+
- Outils spécialisés
|
| 249 |
+
- Ressources nécessaires
|
| 250 |
+
- Planning détaillé
|
| 251 |
|
| 252 |
+
3. ANALYSE & DÉVELOPPEMENT
|
| 253 |
+
- Points clés
|
| 254 |
+
- Facteurs critiques
|
| 255 |
+
- Opportunités
|
| 256 |
+
- Risques potentiels
|
| 257 |
|
| 258 |
+
4. RECOMMANDATIONS
|
| 259 |
+
- Solutions proposées
|
| 260 |
+
- Actions concrètes
|
| 261 |
+
- Ressources requises
|
| 262 |
+
- Timeline
|
| 263 |
|
| 264 |
+
5. SUIVI & MESURES
|
| 265 |
+
- KPIs pertinents
|
| 266 |
+
- Outils de mesure
|
| 267 |
+
- Points de contrôle
|
| 268 |
+
- Optimisation continue"""
|
| 269 |
|
| 270 |
def create_interface():
|
| 271 |
+
system = MultiExpertSystem()
|
| 272 |
|
| 273 |
with gr.Blocks() as demo:
|
| 274 |
gr.Markdown("# Optimiseur de Prompts IA Multi-Expert")
|
| 275 |
|
| 276 |
with gr.Row():
|
| 277 |
with gr.Column():
|
| 278 |
+
input_text = gr.Textbox(
|
| 279 |
+
label="Prompt Initial",
|
| 280 |
+
placeholder="Décrivez votre demande...",
|
| 281 |
+
lines=3
|
| 282 |
+
)
|
| 283 |
+
mode = gr.Radio(
|
| 284 |
+
["expert", "creative"],
|
| 285 |
+
value="expert",
|
| 286 |
+
label="Mode"
|
| 287 |
+
)
|
| 288 |
+
complexity = gr.Slider(
|
| 289 |
+
minimum=0,
|
| 290 |
+
maximum=100,
|
| 291 |
+
value=85,
|
| 292 |
+
label="Niveau de Détail"
|
| 293 |
+
)
|
| 294 |
optimize_btn = gr.Button("Optimiser")
|
| 295 |
|
| 296 |
with gr.Column():
|
| 297 |
+
output = gr.Textbox(
|
| 298 |
+
label="Prompt Optimisé",
|
| 299 |
+
lines=15
|
| 300 |
+
)
|
| 301 |
|
| 302 |
optimize_btn.click(
|
| 303 |
fn=system.optimize_prompt,
|