TaruniSwathi commited on
Commit
b9a2f08
·
verified ·
1 Parent(s): e1e87dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -83,7 +83,29 @@ def clean_output(text: str) -> str:
83
 
84
  return text
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
 
 
87
  @spaces.GPU(duration=120)
88
  def generate_code(task: str, user_input: str) -> str:
89
  if not user_input or not user_input.strip():
@@ -240,26 +262,7 @@ into equivalent C# using a fine-tuned Qwen2.5-Coder model.
240
  ],
241
  )
242
 
243
- def _clean_csharp_output(code: str) -> str:
244
- """
245
- Remove spurious `virtual` / `override` modifiers the model adds to bare
246
- (class-less) method snippets.
247
 
248
- The model was trained on C# methods that usually live inside a class, where
249
- `public virtual ...` is common. When it translates a *standalone* Java method
250
- it carries the `virtual` keyword over — but `virtual`/`override` are only
251
- valid on members of a class, so on a bare snippet they are invalid C#.
252
- We therefore strip them ONLY when the snippet has no enclosing type
253
- declaration (class / struct / interface / record / enum).
254
- """
255
- if re.search(r"\b(class|struct|interface|record|enum)\b", code):
256
- return code # real type present — leave modifiers intact
257
- # Drop 'virtual'/'override' after an access modifier: 'public virtual int' -> 'public int'.
258
- code = re.sub(r"\b(public|private|protected|internal)\s+(?:virtual|override)\s+",
259
- r"\1 ", code)
260
- # Drop a leading 'virtual'/'override' with no access modifier.
261
- code = re.sub(r"(^|\n)(\s*)(?:virtual|override)\s+", r"\1\2", code)
262
- return code
263
 
264
  if __name__ == "__main__":
265
  demo.queue(
 
83
 
84
  return text
85
 
86
+ def _clean_csharp_output(text: str) -> str:
87
+ """
88
+ Remove spurious `virtual` / `override` modifiers the model adds to bare
89
+ (class-less) method snippets.
90
+
91
+ The model was trained on C# methods that usually live inside a class, where
92
+ `public virtual ...` is common. When it translates a *standalone* Java method
93
+ it carries the `virtual` keyword over — but `virtual`/`override` are only
94
+ valid on members of a class, so on a bare snippet they are invalid C#.
95
+ We therefore strip them ONLY when the snippet has no enclosing type
96
+ declaration (class / struct / interface / record / enum).
97
+ """
98
+ if re.search(r"\b(class|struct|interface|record|enum)\b", code):
99
+ return code # real type present — leave modifiers intact
100
+ # Drop 'virtual'/'override' after an access modifier: 'public virtual int' -> 'public int'.
101
+ code = re.sub(r"\b(public|private|protected|internal)\s+(?:virtual|override)\s+",
102
+ r"\1 ", code)
103
+ # Drop a leading 'virtual'/'override' with no access modifier.
104
+ code = re.sub(r"(^|\n)(\s*)(?:virtual|override)\s+", r"\1\2", code)
105
+ return code
106
 
107
+
108
+
109
  @spaces.GPU(duration=120)
110
  def generate_code(task: str, user_input: str) -> str:
111
  if not user_input or not user_input.strip():
 
262
  ],
263
  )
264
 
 
 
 
 
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  if __name__ == "__main__":
268
  demo.queue(