Cenaashoori commited on
Commit
0a92c23
1 Parent(s): 48e8a0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -2
app.py CHANGED
@@ -1,6 +1,36 @@
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
5
 
6
  def format_prompt(message, history):
@@ -27,7 +57,11 @@ def generate(
27
  do_sample=True,
28
  seed=42,
29
  )
30
-
 
 
 
 
31
  formatted_prompt = format_prompt(prompt, history)
32
 
33
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
@@ -44,7 +78,7 @@ mychatbot = gr.Chatbot(
44
 
45
  demo = gr.ChatInterface(fn=generate,
46
  chatbot=mychatbot,
47
- title="Tomoniai's Mixtral 8x7b Chat",
48
  retry_btn=None,
49
  undo_btn=None
50
  )
 
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
4
+ import re
5
+
6
+ # Define regex patterns for comments
7
+ java_single_line_comment_regex = r"\/\/.*"
8
+ java_multiline_comment_regex = r"\/\*(?:[^*]|\*(?!\/))*\*\/"
9
+ kotlin_single_line_comment_regex = r"\/\/.*"
10
+ kotlin_multiline_comment_regex = r"\/\*(?:[^*]|\*(?!\/))*\*\/"
11
+
12
+
13
+ def remove_comments(content,file_type):
14
+ """
15
+ Opens a Java or Kotlin file, removes comments, and saves the changes.
16
+
17
+ Args:
18
+ file_path: The path to the Java or Kotlin file.
19
+ """
20
+
21
+
22
+ # Determine file type based on extension
23
+ if file_type == "java":
24
+ pattern = java_single_line_comment_regex + "|" + java_multiline_comment_regex
25
+ elif file_type == "kotlin":
26
+ pattern = kotlin_single_line_comment_regex + "|" + kotlin_multiline_comment_regex
27
+ else:
28
+ raise ValueError(f"Unsupported file type: {file_type}")
29
+
30
+ # Remove comments using regex
31
+ clean_content = re.sub(pattern, "", content, )
32
+ return clean_content
33
+
34
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
35
 
36
  def format_prompt(message, history):
 
57
  do_sample=True,
58
  seed=42,
59
  )
60
+ prompt = f"""Translate the given Kotlin code to Java, adhering to the following constraints:
61
+ Preserve the original names of classes, fields, and methods without renaming.
62
+ {remove_comments(
63
+ content=prompt,file_type='kotlin'
64
+ ).strip()}"""
65
  formatted_prompt = format_prompt(prompt, history)
66
 
67
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
 
78
 
79
  demo = gr.ChatInterface(fn=generate,
80
  chatbot=mychatbot,
81
+ title="Mixtral 8x7b Chat For Kotlin Translation",
82
  retry_btn=None,
83
  undo_btn=None
84
  )