Mahavaury2 commited on
Commit
73e29aa
·
verified ·
1 Parent(s): 13de298

Update app.py + style.css

Browse files

Modification de la description, ajouts des 10 questions de base dans app.py
Dans le tyle.css, ajout d'un dégradé pastel

Files changed (1) hide show
  1. app.py +27 -55
app.py CHANGED
@@ -9,13 +9,11 @@ import spaces
9
  import torch
10
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
11
 
12
- DESCRIPTION = "# Mistral-7B v0.3"
13
 
14
  if not torch.cuda.is_available():
15
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
16
 
17
- MAX_MAX_NEW_TOKENS = 2048
18
- DEFAULT_MAX_NEW_TOKENS = 1024
19
  MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
20
 
21
  if torch.cuda.is_available():
@@ -25,18 +23,22 @@ if torch.cuda.is_available():
25
 
26
 
27
  @spaces.GPU
28
- def generate(
29
- message: str,
30
- chat_history: list[dict],
31
- max_new_tokens: int = 1024,
32
- temperature: float = 0.6,
33
- top_p: float = 0.9,
34
- top_k: int = 50,
35
- repetition_penalty: float = 1.2,
36
- ) -> Iterator[str]:
37
- conversation = [*chat_history, {"role": "user", "content": message}]
 
38
 
 
 
39
  input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
 
40
  if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
41
  input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
42
  gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
@@ -63,52 +65,22 @@ def generate(
63
  yield "".join(outputs)
64
 
65
 
 
66
  demo = gr.ChatInterface(
67
  fn=generate,
68
- additional_inputs=[
69
- gr.Slider(
70
- label="Max new tokens",
71
- minimum=1,
72
- maximum=MAX_MAX_NEW_TOKENS,
73
- step=1,
74
- value=DEFAULT_MAX_NEW_TOKENS,
75
- ),
76
- gr.Slider(
77
- label="Temperature",
78
- minimum=0.1,
79
- maximum=4.0,
80
- step=0.1,
81
- value=0.6,
82
- ),
83
- gr.Slider(
84
- label="Top-p (nucleus sampling)",
85
- minimum=0.05,
86
- maximum=1.0,
87
- step=0.05,
88
- value=0.9,
89
- ),
90
- gr.Slider(
91
- label="Top-k",
92
- minimum=1,
93
- maximum=1000,
94
- step=1,
95
- value=50,
96
- ),
97
- gr.Slider(
98
- label="Repetition penalty",
99
- minimum=1.0,
100
- maximum=2.0,
101
- step=0.05,
102
- value=1.2,
103
- ),
104
- ],
105
  stop_btn=None,
106
  examples=[
107
- ["Hello there! How are you doing?"],
108
- ["Can you explain briefly to me what is the Python programming language?"],
109
- ["Explain the plot of Cinderella in a sentence."],
110
- ["How many hours does it take a man to eat a Helicopter?"],
111
- ["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
 
 
 
 
 
 
112
  ],
113
  type="messages",
114
  description=DESCRIPTION,
 
9
  import torch
10
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
11
 
12
+ DESCRIPTION = "# L'IA qui t'informe sur tes désirs"
13
 
14
  if not torch.cuda.is_available():
15
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
16
 
 
 
17
  MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
18
 
19
  if torch.cuda.is_available():
 
23
 
24
 
25
  @spaces.GPU
26
+ def generate(message: str, chat_history: list[dict]) -> Iterator[str]:
27
+ """Fonction de génération sans sliders : les paramètres
28
+ de génération (max_new_tokens, température, etc.) sont
29
+ fixés en dur.
30
+ """
31
+ # Valeurs par défaut fixées
32
+ max_new_tokens = 1024
33
+ temperature = 0.6
34
+ top_p = 0.9
35
+ top_k = 50
36
+ repetition_penalty = 1.2
37
 
38
+ # Prépare la conversation
39
+ conversation = [*chat_history, {"role": "user", "content": message}]
40
  input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
41
+
42
  if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
43
  input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
44
  gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
 
65
  yield "".join(outputs)
66
 
67
 
68
+ # On ne fournit plus 'additional_inputs' ici, donc aucun slider ne sera affiché
69
  demo = gr.ChatInterface(
70
  fn=generate,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  stop_btn=None,
72
  examples=[
73
+ ["C’est quoi le consentement ? Comment savoir si ma copine a envie de moi ?"],
74
+ ["C’est quoi une agression sexuelle ?"],
75
+ ["C’est quoi un viol ?"],
76
+ ["C’est quoi un attouchement ?"],
77
+ ["C’est quoi un harcèlement sexuel ?"],
78
+ ["Est-ce illégal de visionner du porno ?"],
79
+ ["C’est quoi un harcèlement sexuel ?"],
80
+ ["Mon copain me demande un nude, dois-je le faire ?"],
81
+ ["Mon ancien copain me menace de poster des photos de moi nue sur internet, que faire ?"],
82
+ ["Que puis-je faire si un membre de ma famille me touche d’une manière bizarre, mais que j’ai peur de parler ou de ne pas être cru ?"
83
+ ],
84
  ],
85
  type="messages",
86
  description=DESCRIPTION,