Commit
·
cfc0929
1
Parent(s):
67912d1
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,9 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import openai
|
4 |
|
5 |
-
|
6 |
-
openai.
|
7 |
-
|
8 |
-
app_username = os.getenv("APP_USERNAME")
|
9 |
-
|
10 |
-
def translate(text):
|
11 |
system_prompt = "Translate Japanese to English. Please output only the translation result."
|
12 |
response = openai.ChatCompletion.create(
|
13 |
model="gpt-3.5-turbo-0613",
|
@@ -20,15 +17,19 @@ def translate(text):
|
|
20 |
)
|
21 |
return response['choices'][0]['message']['content']
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
demo.launch(
|
|
|
2 |
import os
|
3 |
import openai
|
4 |
|
5 |
+
def translate(text, api_key, api_organization=None):
|
6 |
+
openai.organization = api_organization
|
7 |
+
openai.api_key = api_key
|
|
|
|
|
|
|
8 |
system_prompt = "Translate Japanese to English. Please output only the translation result."
|
9 |
response = openai.ChatCompletion.create(
|
10 |
model="gpt-3.5-turbo-0613",
|
|
|
17 |
)
|
18 |
return response['choices'][0]['message']['content']
|
19 |
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
gr.Markdown("Demo-app for Japanese -> English translation using GPT-3.5")
|
22 |
+
with gr.Accordion("OpenAI API Settings", open=False):
|
23 |
+
api_key = gr.Textbox(label="OpenAI API key", placeholder="OpenAI API key")
|
24 |
+
api_organization = gr.Textbox(label="OpenAI API organization", placeholder="OpenAI API organization (optional)")
|
25 |
+
with gr.Row():
|
26 |
+
inp = gr.Textbox(label="Input", placeholder="Japanese")
|
27 |
+
out = gr.Textbox(label="Output")
|
28 |
+
examples = gr.Examples(
|
29 |
+
[["こんにちは。今日もいい天気ですね。"],["身から出た錆"]],
|
30 |
+
[inp],
|
31 |
+
)
|
32 |
+
btn = gr.Button("Translate")
|
33 |
+
btn.click(fn=translate, inputs=[inp, api_key, api_organization], outputs=out)
|
34 |
|
35 |
+
demo.launch()
|