Spaces:
Build error
Build error
Download app.py from BOBOBO-Coder/Test: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/BOBOBO-Coder/Test/resolve/main/app.py
- Command line
-
hf download hf://spaces/BOBOBO-Coder/Test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/BOBOBO-Coder/Test/resolve/main/app.py
1.06 kB
| import gradio as gr | |
| from openai import OpenAI | |
| with gr.Blocks() as demo: | |
| with gr.Column(): | |
| gr.HTML("<h1>hello</h1>") | |
| gr.HTML("<h3>who r u?</h3>") | |
| inbox = gr.Textbox(label="输入中文") | |
| btn = gr.Button() | |
| outbox = gr.Textbox(label="输出语句") | |
| def fn(text): | |
| client = OpenAI(api_key = 'sk-svcacct-D_doQ9x98ixnbQa2AR86F-bEqlqoid101TOcoLT9duKdT3BlbkFJYpCHkFdlLhP9k-vegZwDmBaskTN0joQ34rdOGmx93BEA') | |
| messages = [{"role": "system", | |
| "content": "你是一个英语母语者,擅长将中文内容翻译成英语,也熟悉宝可梦这样动漫的一些人物名称,接下来我给出一段中文文本,你将直接进行翻译输出英文"}] | |
| messages.append({"role": "user", "content": text}) | |
| response = client.chat.completions.create(model="gpt-4o", messages=messages) | |
| raise gr.Warning("1111") | |
| return response.choices[0].message.content | |
| btn.click(fn,inbox,outbox) | |
| if __name__ == "__main__": | |
| demo.launch() |