Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,22 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
with gr.Blocks() as demo:
|
| 4 |
with gr.Column():
|
| 5 |
gr.HTML("<h1>hello</h1>")
|
| 6 |
gr.HTML("<h3>who r u?</h3>")
|
| 7 |
-
inbox = gr.Textbox(label="输入
|
|
|
|
| 8 |
outbox = gr.Textbox(label="输出语句")
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
|
| 5 |
with gr.Blocks() as demo:
|
| 6 |
with gr.Column():
|
| 7 |
gr.HTML("<h1>hello</h1>")
|
| 8 |
gr.HTML("<h3>who r u?</h3>")
|
| 9 |
+
inbox = gr.Textbox(label="输入中文")
|
| 10 |
+
btn = gr.Button()
|
| 11 |
outbox = gr.Textbox(label="输出语句")
|
| 12 |
+
def fn(text):
|
| 13 |
+
client = OpenAI(api_key = 'sk-svcacct-D_doQ9x98ixnbQa2AR86F-bEqlqoid101TOcoLT9duKdT3BlbkFJYpCHkFdlLhP9k-vegZwDmBaskTN0joQ34rdOGmx93BEA')
|
| 14 |
+
messages = [{"role": "system",
|
| 15 |
+
"content": "你是一个英语母语者,擅长将中文内容翻译成英语,也熟悉宝可梦这样动漫的一些人物名称,接下来我给出一段中文文本,你将直接进行翻译输出英文"}]
|
| 16 |
+
messages.append({"role": "user", "content": text})
|
| 17 |
+
response = client.chat.completions.create(model="gpt-4o", messages=messages)
|
| 18 |
+
return response.choices[0].message.content
|
| 19 |
+
btn.click(fn,inbox,outbox)
|
| 20 |
|
| 21 |
|
| 22 |
|