Pclanglais commited on
Commit
bafe915
1 Parent(s): d4b1191

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -14
app.py CHANGED
@@ -30,8 +30,8 @@ css = """
30
  size:1.2em;
31
  }
32
  :target {
33
- background-color: #CCF3DF; /* Change the text color to red */
34
- }
35
  .source {
36
  float:left;
37
  max-width:17%;
@@ -42,16 +42,16 @@ css = """
42
  cursor: pointer;
43
  font-variant-position: super;
44
  color: #97999b;
45
- }
46
 
47
- .tooltip:hover::after {
48
  content: attr(data-text);
49
  position: absolute;
50
  left: 0;
51
- top: 120%; /* Adjust this value as needed to control the vertical spacing between the text and the tooltip */
52
- white-space: pre-wrap; /* Allows the text to wrap */
53
- width: 500px; /* Sets a fixed maximum width for the tooltip */
54
- max-width: 500px; /* Ensures the tooltip does not exceed the maximum width */
55
  z-index: 1;
56
  background-color: #f9f9f9;
57
  color: #000;
@@ -59,10 +59,33 @@ css = """
59
  border-radius: 5px;
60
  padding: 5px;
61
  display: block;
62
- box-shadow: 0 4px 8px rgba(0,0,0,0.1); /* Optional: Adds a subtle shadow for better visibility */
63
- }"""
 
 
 
 
 
 
 
 
 
64
 
65
- #Curtesy of chatgpt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  # Class to encapsulate the Falcon chatbot
68
  class MistralChatBot:
@@ -71,12 +94,16 @@ class MistralChatBot:
71
 
72
  def predict(self, user_message):
73
  sampling_params = SamplingParams(temperature=0.9, top_p=0.95, max_tokens=4000, presence_penalty=0, stop=["#END#"])
74
- detailed_prompt = correction = f"### TEXT ###\n{user_message}\n\n### CORRECTION ###\n"
75
  print(detailed_prompt)
76
  prompts = [detailed_prompt]
77
- outputs = llm.generate(prompts, sampling_params, use_tqdm = False)
78
  generated_text = outputs[0].outputs[0].text
79
- generated_text = '<h2 style="text-align:center">Réponse</h3>\n<div class="generation">' + generated_text + "</div>"
 
 
 
 
80
  return generated_text
81
 
82
  # Create the Falcon chatbot instance
 
30
  size:1.2em;
31
  }
32
  :target {
33
+ background-color: #CCF3DF;
34
+ }
35
  .source {
36
  float:left;
37
  max-width:17%;
 
42
  cursor: pointer;
43
  font-variant-position: super;
44
  color: #97999b;
45
+ }
46
 
47
+ .tooltip:hover::after {
48
  content: attr(data-text);
49
  position: absolute;
50
  left: 0;
51
+ top: 120%;
52
+ white-space: pre-wrap;
53
+ width: 500px;
54
+ max-width: 500px;
55
  z-index: 1;
56
  background-color: #f9f9f9;
57
  color: #000;
 
59
  border-radius: 5px;
60
  padding: 5px;
61
  display: block;
62
+ box-shadow: 0 4px 8px rgba(0,0,0,0.1);
63
+ }
64
+ /* New styles for diff */
65
+ .deleted {
66
+ background-color: #ffcccb;
67
+ text-decoration: line-through;
68
+ }
69
+ .inserted {
70
+ background-color: #90EE90;
71
+ }
72
+ """
73
 
74
+ #Curtesy of claude
75
+ def generate_html_diff(old_text, new_text):
76
+ d = difflib.Differ()
77
+ diff = list(d.compare(old_text.split(), new_text.split()))
78
+
79
+ html_diff = []
80
+ for word in diff:
81
+ if word.startswith(' '):
82
+ html_diff.append(word[2:])
83
+ elif word.startswith('- '):
84
+ html_diff.append(f'<span style="background-color: #ffcccb; text-decoration: line-through;">{word[2:]}</span>')
85
+ elif word.startswith('+ '):
86
+ html_diff.append(f'<span style="background-color: #90EE90;">{word[2:]}</span>')
87
+
88
+ return ' '.join(html_diff)
89
 
90
  # Class to encapsulate the Falcon chatbot
91
  class MistralChatBot:
 
94
 
95
  def predict(self, user_message):
96
  sampling_params = SamplingParams(temperature=0.9, top_p=0.95, max_tokens=4000, presence_penalty=0, stop=["#END#"])
97
+ detailed_prompt = f"### TEXT ###\n{user_message}\n\n### CORRECTION ###\n"
98
  print(detailed_prompt)
99
  prompts = [detailed_prompt]
100
+ outputs = llm.generate(prompts, sampling_params, use_tqdm=False)
101
  generated_text = outputs[0].outputs[0].text
102
+
103
+ # Generate HTML diff
104
+ html_diff = generate_html_diff(user_message, generated_text)
105
+
106
+ generated_text = '<h2 style="text-align:center">Réponse</h3>\n<div class="generation">' + html_diff + "</div>"
107
  return generated_text
108
 
109
  # Create the Falcon chatbot instance