Commit
·
c2b596d
1
Parent(s):
0244879
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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",
|
14 |
+
messages=[
|
15 |
+
{'role': 'system', 'content': system_prompt},
|
16 |
+
{'role': 'user', 'content': text},
|
17 |
+
],
|
18 |
+
frequency_penalty = 0.0,
|
19 |
+
temperature=0.0,
|
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=True, auth=(app_username, app_password))
|