dovedovepigeon commited on
Commit
cfc0929
·
1 Parent(s): 67912d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -2,12 +2,9 @@ import gradio as gr
2
  import os
3
  import openai
4
 
5
- openai.organization = os.getenv("API_ORG")
6
- openai.api_key = os.getenv("API_KEY")
7
- app_password = os.getenv("APP_PASSWORD")
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
- demo = gr.Interface(
24
- fn=translate,
25
- inputs=gr.components.Textbox(label="Text", placeholder="英語に翻訳したい日本語の文を入力してください。"),
26
- outputs=["text"],
27
- examples=["こんにちは。今日もいい天気ですね。", "身から出た錆"],
28
- cache_examples=False,
29
- flagging_options=[],
30
- title="日英翻訳",
31
- description="GPT-3.5を利用した日本語->英語翻訳のデモ"
32
- )
 
 
 
 
33
 
34
- demo.launch(share=False, auth=(app_username, app_password))
 
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()