brackozi commited on
Commit
0ec4113
·
1 Parent(s): a3f7d78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -11,7 +11,7 @@ def translate_code(code, from_language, to_language):
11
  response = openai.Completion.create(
12
  engine="davinci-codex",
13
  prompt=prompt,
14
- max_tokens=2000,
15
  n=1,
16
  stop=None,
17
  temperature=0.5,
@@ -19,6 +19,8 @@ def translate_code(code, from_language, to_language):
19
 
20
  translated_code = response.choices[0].text.strip()
21
  return translated_code
 
 
22
 
23
  languages = [
24
  "Python",
@@ -39,7 +41,7 @@ iface = gr.Interface(
39
  gr.inputs.Dropdown(choices=languages, label="From Language"),
40
  gr.inputs.Dropdown(choices=languages, label="To Language"),
41
  ],
42
- outputs=gr.outputs.Textarea(label="Translated Code"),
43
  title="Code Translator",
44
  description="Translate code between different programming languages using OpenAI.",
45
  )
 
11
  response = openai.Completion.create(
12
  engine="davinci-codex",
13
  prompt=prompt,
14
+ max_tokens=200,
15
  n=1,
16
  stop=None,
17
  temperature=0.5,
 
19
 
20
  translated_code = response.choices[0].text.strip()
21
  return translated_code
22
+ except Exception as e:
23
+ return f"Error: {str(e)}"
24
 
25
  languages = [
26
  "Python",
 
41
  gr.inputs.Dropdown(choices=languages, label="From Language"),
42
  gr.inputs.Dropdown(choices=languages, label="To Language"),
43
  ],
44
+ outputs=gr.outputs.Textbox(label="Translated Code"),
45
  title="Code Translator",
46
  description="Translate code between different programming languages using OpenAI.",
47
  )