Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,33 +8,33 @@ openai.api_key = os.environ["OPENAI_API_KEY"]
|
|
8 |
|
9 |
def translate_code(code, from_language, to_language):
|
10 |
if from_language == "JavaScript" and to_language == "Java":
|
11 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices.
|
12 |
elif from_language == "Java" and to_language == "JavaScript":
|
13 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows JavaScript syntax and idioms, considering language-specific best practices.
|
14 |
elif from_language == "C++" and to_language == "Java":
|
15 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices.
|
16 |
elif from_language == "Java" and to_language == "C++":
|
17 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows C++ syntax and idioms, considering language-specific best practices.
|
18 |
elif from_language == "C#" and to_language == "Java":
|
19 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices.
|
20 |
elif from_language == "Java" and to_language == "C#":
|
21 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows C# syntax and idioms, considering language-specific best practices.
|
22 |
elif from_language == "Ruby" and to_language == "Java":
|
23 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices.
|
24 |
elif from_language == "Java" and to_language == "Ruby":
|
25 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Ruby syntax and idioms, considering language-specific best practices.
|
26 |
elif from_language == "Swift" and to_language == "Python":
|
27 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Python syntax and idioms, considering language-specific best practices.
|
28 |
elif from_language == "Python" and to_language == "Swift":
|
29 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Swift syntax and idioms, considering language-specific best practices.
|
30 |
elif from_language == "Go" and to_language == "Java":
|
31 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices.
|
32 |
elif from_language == "Java" and to_language == "Go":
|
33 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Go syntax and idioms, considering language-specific best practices.
|
34 |
elif from_language == "PHP" and to_language == "Java":
|
35 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices.
|
36 |
elif from_language == "Java" and to_language == "PHP":
|
37 |
-
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows PHP syntax and idioms, considering language-specific best practices.
|
38 |
else:
|
39 |
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nKeep the translation accurate and idiomatic, considering language-specific best practices."
|
40 |
|
|
|
8 |
|
9 |
def translate_code(code, from_language, to_language):
|
10 |
if from_language == "JavaScript" and to_language == "Java":
|
11 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices. add required import statements."
|
12 |
elif from_language == "Java" and to_language == "JavaScript":
|
13 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows JavaScript syntax and idioms, considering language-specific best practices. add required modules."
|
14 |
elif from_language == "C++" and to_language == "Java":
|
15 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices. add required import statements."
|
16 |
elif from_language == "Java" and to_language == "C++":
|
17 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows C++ syntax and idioms, considering language-specific best practices. Include required headers."
|
18 |
elif from_language == "C#" and to_language == "Java":
|
19 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices. add required import statements."
|
20 |
elif from_language == "Java" and to_language == "C#":
|
21 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows C# syntax and idioms, considering language-specific best practices. add required using statements."
|
22 |
elif from_language == "Ruby" and to_language == "Java":
|
23 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices. add required import statements."
|
24 |
elif from_language == "Java" and to_language == "Ruby":
|
25 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Ruby syntax and idioms, considering language-specific best practices. add required gems/libraries."
|
26 |
elif from_language == "Swift" and to_language == "Python":
|
27 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Python syntax and idioms, considering language-specific best practices. add required modules."
|
28 |
elif from_language == "Python" and to_language == "Swift":
|
29 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Swift syntax and idioms, considering language-specific best practices. add required frameworks."
|
30 |
elif from_language == "Go" and to_language == "Java":
|
31 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices. add required import statements."
|
32 |
elif from_language == "Java" and to_language == "Go":
|
33 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Go syntax and idioms, considering language-specific best practices. add required packages."
|
34 |
elif from_language == "PHP" and to_language == "Java":
|
35 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows Java syntax and idioms, considering language-specific best practices. add required import statements."
|
36 |
elif from_language == "Java" and to_language == "PHP":
|
37 |
+
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nEnsure that the translation follows PHP syntax and idioms, considering language-specific best practices. add required packages/libraries."
|
38 |
else:
|
39 |
context = f"Translate the following {from_language} code snippet to {to_language}:\n\n{code}\n\nKeep the translation accurate and idiomatic, considering language-specific best practices."
|
40 |
|