Spaces:
Sleeping
Sleeping
Pclanglais
commited on
Commit
•
bafe915
1
Parent(s):
d4b1191
Update app.py
Browse files
app.py
CHANGED
@@ -30,8 +30,8 @@ css = """
|
|
30 |
size:1.2em;
|
31 |
}
|
32 |
:target {
|
33 |
-
background-color: #CCF3DF;
|
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 |
-
|
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,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);
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
#Curtesy of
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 =
|
75 |
print(detailed_prompt)
|
76 |
prompts = [detailed_prompt]
|
77 |
-
outputs = llm.generate(prompts, sampling_params, use_tqdm
|
78 |
generated_text = outputs[0].outputs[0].text
|
79 |
-
|
|
|
|
|
|
|
|
|
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
|