Jaume commited on
Commit
e4a0928
·
1 Parent(s): 27346c0

fix empty correction

Browse files
Files changed (3) hide show
  1. README.md +6 -2
  2. review.py +14 -5
  3. templates/deletion.html +1 -0
README.md CHANGED
@@ -10,9 +10,13 @@ pinned: true
10
  license: mit
11
  ---
12
 
13
- # ✅ Write4All
14
 
15
- In a world where diversity and inclusivity are essential, crafting content that resonates with everyone can be a challenge. With ✅ Write4All I hope making the world more inclusive, one word and image at a time.
 
 
 
 
16
 
17
  ## Requirements
18
 
 
10
  license: mit
11
  ---
12
 
13
+ # ✅Write4All
14
 
15
+ In a world where diversity and inclusivity are essential, crafting content that resonates with everyone can be a challenge. With ✅Write4All I hope making the world more inclusive, one word and image at a time.
16
+
17
+ See it in action in:
18
+ - HuggingFace Spaces: [✅Write4All](https://huggingface.co/spaces/Jaume/Write4All).
19
+ - Examples notebook: [✅Write4All Examples](./notebooks/examples.ipynb)
20
 
21
  ## Requirements
22
 
review.py CHANGED
@@ -46,13 +46,15 @@ gemini_1_0_vision = genai.GenerativeModel(
46
 
47
  genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
48
 
 
49
  @cache
50
  def get_file(relative_path: str) -> str:
51
  current_path = os.path.dirname(os.path.abspath(__file__))
52
  full_path = os.path.join(current_path, relative_path)
53
  with open(full_path) as f:
54
  return f.read()
55
-
 
56
  def fix_json(json_str: str) -> str:
57
  template = get_file("templates/prompt_json_fix.txt")
58
  prompt = template.format(json=json_str)
@@ -90,9 +92,14 @@ def apply_review(text: str, review: list[dict]) -> str:
90
  start = starts[0]
91
  end = start + len(entity["term"])
92
  output += text[last_end:start]
93
- output += get_file("templates/correction.html").format(
94
- term=text[start:end], fix=entity["fix"], kind=entity["type"]
95
- )
 
 
 
 
 
96
  last_end = end
97
  output += text[last_end:]
98
  return f"<pre style='white-space: pre-wrap;'>{output}</pre>"
@@ -105,6 +112,7 @@ def review_table_summary(review: list[dict]) -> str:
105
  table += "</table>"
106
  return table
107
 
 
108
  def review_text(text: str, text_model: genai.GenerativeModel) -> list[dict]:
109
  template = get_file("templates/prompt_v1.txt")
110
  try:
@@ -116,6 +124,7 @@ def review_text(text: str, text_model: genai.GenerativeModel) -> list[dict]:
116
  )
117
  return get_json_content(response)
118
 
 
119
  def process_text(model: str, text: str) -> str:
120
  text_model = gemini_1_0 if model == "Gemini 1.0 Pro" else gemini_1_5
121
  review = review_text(text, text_model)
@@ -142,4 +151,4 @@ def review_image(image, vision_model: genai.GenerativeModel) -> list[dict]:
142
 
143
  def process_image(model: str, image):
144
  vision_model = gemini_1_0_vision if model == "Gemini 1.0 Pro Vision" else gemini_1_5
145
- return review_image(image, vision_model)
 
46
 
47
  genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
48
 
49
+
50
  @cache
51
  def get_file(relative_path: str) -> str:
52
  current_path = os.path.dirname(os.path.abspath(__file__))
53
  full_path = os.path.join(current_path, relative_path)
54
  with open(full_path) as f:
55
  return f.read()
56
+
57
+
58
  def fix_json(json_str: str) -> str:
59
  template = get_file("templates/prompt_json_fix.txt")
60
  prompt = template.format(json=json_str)
 
92
  start = starts[0]
93
  end = start + len(entity["term"])
94
  output += text[last_end:start]
95
+ if len(entity["fix"]) > 0:
96
+ output += get_file("templates/correction.html").format(
97
+ term=text[start:end], fix=entity["fix"], kind=entity["type"]
98
+ )
99
+ else:
100
+ output += get_file("templates/deletion.html").format(
101
+ term=text[start:end], kind=entity["type"]
102
+ )
103
  last_end = end
104
  output += text[last_end:]
105
  return f"<pre style='white-space: pre-wrap;'>{output}</pre>"
 
112
  table += "</table>"
113
  return table
114
 
115
+
116
  def review_text(text: str, text_model: genai.GenerativeModel) -> list[dict]:
117
  template = get_file("templates/prompt_v1.txt")
118
  try:
 
124
  )
125
  return get_json_content(response)
126
 
127
+
128
  def process_text(model: str, text: str) -> str:
129
  text_model = gemini_1_0 if model == "Gemini 1.0 Pro" else gemini_1_5
130
  review = review_text(text, text_model)
 
151
 
152
  def process_image(model: str, image):
153
  vision_model = gemini_1_0_vision if model == "Gemini 1.0 Pro Vision" else gemini_1_5
154
+ return review_image(image, vision_model)
templates/deletion.html ADDED
@@ -0,0 +1 @@
 
 
1
+ <span title="{kind}"><span style='background-color:#FF5555; color:black; text-decoration:line-through; text-decoration-thickness: 2px; min-height: 22px; display: inline-block; border-radius: 5px 5px 5px 5px; padding-left: 5px; padding-right: 5px;'>{term}</span></span>