Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,241 +1,175 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
class
|
| 4 |
def __init__(self):
|
| 5 |
-
self.
|
| 6 |
-
"finance":
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
{
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
-
|
| 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 |
-
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
{implementation}
|
| 38 |
-
|
| 39 |
-
Documentation :
|
| 40 |
-
- Plans d'exécution
|
| 41 |
-
- Cahier des charges
|
| 42 |
-
- Planning prévisionnel
|
| 43 |
-
- Budget estimatif"""
|
| 44 |
-
},
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
| 50 |
Analyse organisationnelle :
|
| 51 |
-
-
|
| 52 |
-
-
|
| 53 |
-
-
|
| 54 |
-
-
|
| 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 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
{
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
-
|
| 120 |
-
-
|
| 121 |
-
-
|
| 122 |
-
-
|
| 123 |
-
-
|
| 124 |
-
}
|
| 125 |
}
|
| 126 |
-
# Intégration avec les domaines précédents
|
| 127 |
-
self.expertise_domains.update(self.get_previous_domains())
|
| 128 |
|
| 129 |
-
def
|
| 130 |
-
# Retourne les domaines d'expertise précédents
|
| 131 |
return {
|
| 132 |
-
"
|
| 133 |
-
"
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
|
| 137 |
-
def
|
| 138 |
-
|
| 139 |
-
for domain, info in self.
|
| 140 |
-
if any(keyword in
|
| 141 |
return domain
|
| 142 |
return "general"
|
| 143 |
|
| 144 |
-
def
|
| 145 |
-
domain = self.
|
| 146 |
-
|
|
|
|
|
|
|
| 147 |
|
| 148 |
-
#
|
| 149 |
-
|
| 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
|
| 164 |
|
| 165 |
Méthodologie :
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 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 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
| 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():
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
lines=3
|
| 212 |
-
)
|
| 213 |
-
|
| 214 |
-
mode = gr.Radio(
|
| 215 |
-
choices=["expert", "creative"],
|
| 216 |
-
value="expert",
|
| 217 |
-
label="Mode"
|
| 218 |
-
)
|
| 219 |
-
|
| 220 |
-
complexity = gr.Slider(
|
| 221 |
-
minimum=0,
|
| 222 |
-
maximum=100,
|
| 223 |
-
value=85,
|
| 224 |
-
label="Niveau de Détail"
|
| 225 |
-
)
|
| 226 |
-
|
| 227 |
optimize_btn = gr.Button("Optimiser")
|
| 228 |
|
| 229 |
with gr.Column():
|
| 230 |
-
output = gr.Textbox(
|
| 231 |
-
label="Prompt Optimisé",
|
| 232 |
-
lines=12
|
| 233 |
-
)
|
| 234 |
|
| 235 |
optimize_btn.click(
|
| 236 |
-
fn=system.
|
| 237 |
-
inputs=[
|
| 238 |
-
outputs=
|
| 239 |
)
|
| 240 |
|
| 241 |
return demo
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
class ExpertSystem:
|
| 4 |
def __init__(self):
|
| 5 |
+
self.domains = {
|
| 6 |
+
"finance": self._get_finance_template(),
|
| 7 |
+
"architecture": self._get_architecture_template(),
|
| 8 |
+
"rh": self._get_rh_template(),
|
| 9 |
+
"innovation": self._get_innovation_template(),
|
| 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 |
+
def _get_image_template(self):
|
| 35 |
+
return {
|
| 36 |
+
"keywords": ["image", "photo", "visuel", "illustration", "dessin"],
|
| 37 |
+
"template": """Créez une photographie ultra-détaillée {text}
|
| 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 |
+
def _get_architecture_template(self):
|
| 59 |
+
return {
|
| 60 |
+
"keywords": ["architecture", "construction", "bâtiment"],
|
| 61 |
+
"template": """Plan architectural détaillé :
|
| 62 |
+
{text}
|
| 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 |
+
def _get_rh_template(self):
|
| 72 |
+
return {
|
| 73 |
+
"keywords": ["rh", "ressources humaines", "recrutement"],
|
| 74 |
+
"template": """Stratégie RH optimisée :
|
| 75 |
+
{text}
|
| 76 |
|
| 77 |
Analyse organisationnelle :
|
| 78 |
+
- Structure proposée
|
| 79 |
+
- Compétences requises
|
| 80 |
+
- Plan de développement
|
| 81 |
+
- KPIs de performance"""
|
| 82 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
def _get_innovation_template(self):
|
| 85 |
+
return {
|
| 86 |
+
"keywords": ["innovation", "r&d", "recherche"],
|
| 87 |
+
"template": """Programme R&D innovant :
|
| 88 |
+
{text}
|
| 89 |
+
|
| 90 |
+
Processus d'innovation :
|
| 91 |
+
- État de l'art
|
| 92 |
+
- Axes de recherche
|
| 93 |
+
- Prototypage
|
| 94 |
+
- Validation technique"""
|
| 95 |
+
}
|
| 96 |
|
| 97 |
+
def _get_psychology_template(self):
|
| 98 |
+
return {
|
| 99 |
+
"keywords": ["psychologie", "comportement", "thérapie"],
|
| 100 |
+
"template": """Analyse psychologique :
|
| 101 |
+
{text}
|
| 102 |
|
| 103 |
+
Méthodologie :
|
| 104 |
+
- Évaluation comportementale
|
| 105 |
+
- Approche thérapeutique
|
| 106 |
+
- Plan d'intervention
|
| 107 |
+
- Objectifs mesurables"""
|
|
|
|
| 108 |
}
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
def _get_data_template(self):
|
|
|
|
| 111 |
return {
|
| 112 |
+
"keywords": ["données", "data", "analyse", "statistiques"],
|
| 113 |
+
"template": """Analyse data science :
|
| 114 |
+
{text}
|
| 115 |
+
|
| 116 |
+
Méthodologie analytique :
|
| 117 |
+
- Collecte et préparation
|
| 118 |
+
- Modélisation statistique
|
| 119 |
+
- Tests et validation
|
| 120 |
+
- Visualisation avancée"""
|
| 121 |
}
|
| 122 |
|
| 123 |
+
def _detect_domain(self, text):
|
| 124 |
+
text = text.lower()
|
| 125 |
+
for domain, info in self.domains.items():
|
| 126 |
+
if any(keyword in text for keyword in info["keywords"]):
|
| 127 |
return domain
|
| 128 |
return "general"
|
| 129 |
|
| 130 |
+
def optimize_prompt(self, text, mode, complexity):
|
| 131 |
+
domain = self._detect_domain(text)
|
| 132 |
+
if domain in self.domains:
|
| 133 |
+
template = self.domains[domain]["template"]
|
| 134 |
+
return template.format(text=text)
|
| 135 |
|
| 136 |
+
# Template général pour les autres cas
|
| 137 |
+
return f"""Analyse experte détaillée : {text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
Niveau de complexité : {complexity}%
|
| 140 |
|
| 141 |
Méthodologie :
|
| 142 |
+
- Analyse approfondie
|
| 143 |
+
- Documentation complète
|
| 144 |
+
- Validation experte
|
| 145 |
+
- Optimisation continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
+
Recommandations :
|
| 148 |
+
- Solutions optimisées
|
| 149 |
+
- Meilleures pratiques
|
| 150 |
+
- Plan d'action
|
| 151 |
+
- Suivi des résultats"""
|
| 152 |
|
| 153 |
+
def create_interface():
|
| 154 |
+
system = ExpertSystem()
|
| 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(label="Prompt Initial", lines=3)
|
| 162 |
+
mode = gr.Radio(["expert", "creative"], value="expert", label="Mode")
|
| 163 |
+
complexity = gr.Slider(0, 100, 85, label="Niveau de Détail")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
optimize_btn = gr.Button("Optimiser")
|
| 165 |
|
| 166 |
with gr.Column():
|
| 167 |
+
output = gr.Textbox(label="Prompt Optimisé", lines=10)
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
optimize_btn.click(
|
| 170 |
+
fn=system.optimize_prompt,
|
| 171 |
+
inputs=[input_text, mode, complexity],
|
| 172 |
+
outputs=output
|
| 173 |
)
|
| 174 |
|
| 175 |
return demo
|