DinoFrog commited on
Commit
807c07d
·
verified ·
1 Parent(s): 62a46dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -21
app.py CHANGED
@@ -5,7 +5,7 @@ from huggingface_hub import InferenceClient
5
  import pandas as pd
6
  import os
7
  import nltk
8
- nltk.download('punkt')
9
  from nltk.tokenize import sent_tokenize
10
 
11
  HF_TOKEN = os.getenv("HF_TOKEN")
@@ -37,16 +37,13 @@ translator_to_fr = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
37
 
38
  # Fonction pour traduire un texte long en le segmentant
39
  def safe_translate_to_fr(text, max_length=512):
40
- # Segmenter le texte en phrases
41
  sentences = sent_tokenize(text)
42
  translated_sentences = []
43
 
44
  for sentence in sentences:
45
- # Traduire chaque phrase individuellement
46
  translated = translator_to_fr(sentence, max_length=max_length)[0]['translation_text']
47
  translated_sentences.append(translated)
48
 
49
- # Recombiner les phrases traduites
50
  return " ".join(translated_sentences)
51
 
52
  # Fonction pour suggérer le meilleur modèle
@@ -100,7 +97,6 @@ def full_analysis(text, mode, detail_mode, count, history):
100
  if lang != "en":
101
  text = translator_to_en(text, max_length=512)[0]['translation_text']
102
 
103
- # Étape 1 : Poser une question à Zephyr pour prédire l'impact économique
104
  prediction_prompt = f"""<|system|>
105
  You are a professional financial analyst AI with expertise in economic forecasting.
106
  </s>
@@ -112,12 +108,10 @@ Assume the event happens (e.g., if the question is "Will the Federal Reserve rai
112
  <|assistant|>"""
113
  prediction_response = call_zephyr_api(prediction_prompt, mode)
114
 
115
- # Étape 2 : Analyser le sentiment de la réponse de Zephyr
116
  result = classifier(prediction_response)[0]
117
  sentiment_output = f"Sentiment prédictif : {result['label']} (Score: {result['score']:.2f})"
118
  sentiment_gauge = create_sentiment_gauge(result['label'], result['score'])
119
 
120
- # Étape 3 : Générer une explication détaillée en fonction du niveau de détail
121
  explanation_prompt = f"""<|system|>
122
  You are a professional financial analyst AI.
123
  </s>
@@ -241,6 +235,43 @@ def launch_app():
241
  .gr-file label::before {
242
  content: '💾 ';
243
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  """
245
 
246
  with gr.Blocks(theme=gr.themes.Base(), css=custom_css) as iface:
@@ -250,24 +281,24 @@ def launch_app():
250
  count = gr.State(0)
251
  history = gr.State([])
252
 
253
- with gr.Row():
254
- with gr.Column(scale=2):
255
  input_text = gr.Textbox(
256
  lines=4,
257
  placeholder="Entrez une question ici (ex. 'La Réserve fédérale augmentera-t-elle ses taux d'intérêt avant 2025 ?')",
258
  label="Question Économique"
259
  )
260
- with gr.Column(scale=1):
261
- mode_selector = gr.Dropdown(
262
- choices=["Rapide", "Équilibré", "Précis"],
263
- value="Équilibré",
264
- label="Mode (longueur et style de réponse)"
265
- )
266
- detail_mode_selector = gr.Dropdown(
267
- choices=["Normal", "Expert"],
268
- value="Normal",
269
- label="Niveau de détail (simplicité ou technicité)"
270
- )
271
 
272
  with gr.Row():
273
  analyze_btn = gr.Button("Analyser")
@@ -299,7 +330,7 @@ def launch_app():
299
  outputs=[download_file]
300
  )
301
 
302
- iface.launch()
303
 
304
  if __name__ == "__main__":
305
  launch_app()
 
5
  import pandas as pd
6
  import os
7
  import nltk
8
+ nltk.download('punkt_tab') # Changement de 'punkt' à 'punkt_tab'
9
  from nltk.tokenize import sent_tokenize
10
 
11
  HF_TOKEN = os.getenv("HF_TOKEN")
 
37
 
38
  # Fonction pour traduire un texte long en le segmentant
39
  def safe_translate_to_fr(text, max_length=512):
 
40
  sentences = sent_tokenize(text)
41
  translated_sentences = []
42
 
43
  for sentence in sentences:
 
44
  translated = translator_to_fr(sentence, max_length=max_length)[0]['translation_text']
45
  translated_sentences.append(translated)
46
 
 
47
  return " ".join(translated_sentences)
48
 
49
  # Fonction pour suggérer le meilleur modèle
 
97
  if lang != "en":
98
  text = translator_to_en(text, max_length=512)[0]['translation_text']
99
 
 
100
  prediction_prompt = f"""<|system|>
101
  You are a professional financial analyst AI with expertise in economic forecasting.
102
  </s>
 
108
  <|assistant|>"""
109
  prediction_response = call_zephyr_api(prediction_prompt, mode)
110
 
 
111
  result = classifier(prediction_response)[0]
112
  sentiment_output = f"Sentiment prédictif : {result['label']} (Score: {result['score']:.2f})"
113
  sentiment_gauge = create_sentiment_gauge(result['label'], result['score'])
114
 
 
115
  explanation_prompt = f"""<|system|>
116
  You are a professional financial analyst AI.
117
  </s>
 
235
  .gr-file label::before {
236
  content: '💾 ';
237
  }
238
+
239
+ .economic-question-section {
240
+ background-image: url('https://images.unsplash.com/photo-1611974789855-9c2a0a7236a3?q=80&w=2070&auto=format&fit=crop');
241
+ background-size: cover;
242
+ background-position: center;
243
+ background-repeat: no-repeat;
244
+ background-color: rgba(42, 42, 74, 0.9);
245
+ background-blend-mode: overlay;
246
+ border-radius: 12px;
247
+ padding: 20px;
248
+ margin: 20px 0;
249
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
250
+ }
251
+
252
+ .economic-question-section .gr-textbox {
253
+ background: rgba(58, 58, 90, 0.8) !important;
254
+ border: 2px solid #FFD700 !important;
255
+ box-shadow: 0 2px 8px rgba(255, 215, 0, 0.2) !important;
256
+ font-size: 18px !important;
257
+ padding: 15px !important;
258
+ }
259
+
260
+ .economic-question-section .gr-textbox:focus {
261
+ border-color: #FFD700 !important;
262
+ box-shadow: 0 0 12px rgba(255, 215, 0, 0.5) !important;
263
+ }
264
+
265
+ .options-section {
266
+ display: flex;
267
+ justify-content: center;
268
+ gap: 20px;
269
+ margin-top: 15px;
270
+ }
271
+
272
+ .options-section .gr-dropdown {
273
+ width: 200px !important;
274
+ }
275
  """
276
 
277
  with gr.Blocks(theme=gr.themes.Base(), css=custom_css) as iface:
 
281
  count = gr.State(0)
282
  history = gr.State([])
283
 
284
+ with gr.Row(elem_classes=["economic-question-section"]):
285
+ with gr.Column(scale=1, min_width=600):
286
  input_text = gr.Textbox(
287
  lines=4,
288
  placeholder="Entrez une question ici (ex. 'La Réserve fédérale augmentera-t-elle ses taux d'intérêt avant 2025 ?')",
289
  label="Question Économique"
290
  )
291
+ with gr.Row(elem_classes=["options-section"]):
292
+ mode_selector = gr.Dropdown(
293
+ choices=["Rapide", "Équilibré", "Précis"],
294
+ value="Équilibré",
295
+ label="Mode (longueur et style de réponse)"
296
+ )
297
+ detail_mode_selector = gr.Dropdown(
298
+ choices=["Normal", "Expert"],
299
+ value="Normal",
300
+ label="Niveau de détail (simplicité ou technicité)"
301
+ )
302
 
303
  with gr.Row():
304
  analyze_btn = gr.Button("Analyser")
 
330
  outputs=[download_file]
331
  )
332
 
333
+ iface.launch(share=True) # Ajout de share=True
334
 
335
  if __name__ == "__main__":
336
  launch_app()