TaruniSwathi commited on
Commit
6e495b9
·
verified ·
1 Parent(s): 77684f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -239,7 +239,26 @@ into equivalent C# using a fine-tuned Qwen2.5-Coder model.
239
  user_input,
240
  ],
241
  )
242
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
  if __name__ == "__main__":
245
  demo.queue(
 
239
  user_input,
240
  ],
241
  )
242
+ def _clean_csharp_output(code: str) -> str:
243
+ """
244
+ Remove spurious `virtual` / `override` modifiers the model adds to bare
245
+ (class-less) method snippets.
246
+
247
+ The model was trained on C# methods that usually live inside a class, where
248
+ `public virtual ...` is common. When it translates a *standalone* Java method
249
+ it carries the `virtual` keyword over — but `virtual`/`override` are only
250
+ valid on members of a class, so on a bare snippet they are invalid C#.
251
+ We therefore strip them ONLY when the snippet has no enclosing type
252
+ declaration (class / struct / interface / record / enum).
253
+ """
254
+ if re.search(r"\b(class|struct|interface|record|enum)\b", code):
255
+ return code # real type present — leave modifiers intact
256
+ # Drop 'virtual'/'override' after an access modifier: 'public virtual int' -> 'public int'.
257
+ code = re.sub(r"\b(public|private|protected|internal)\s+(?:virtual|override)\s+",
258
+ r"\1 ", code)
259
+ # Drop a leading 'virtual'/'override' with no access modifier.
260
+ code = re.sub(r"(^|\n)(\s*)(?:virtual|override)\s+", r"\1\2", code)
261
+ return code
262
 
263
  if __name__ == "__main__":
264
  demo.queue(