File size: 1,846 Bytes
ed3ce94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import gradio as gr
from openai import OpenAI

# 从环境变量加载API密钥
client = OpenAI(
    api_key=os.getenv("DEEPSEEK_API_KEY"),
    base_url="https://api.deepseek.com"
)

def generate_scenery(lyrics):
    """将中文歌词转换为纯自然风景描写的英文文本"""
    response = client.chat.completions.create(
        model="deepseek-chat",
        messages=[
            {"role": "system", "content": "你是一位自然诗人,请将中文歌词转化为英文的纯风景描写,严格避免任何人称代词或人物动作。只描述自然现象如风、光、水、植物等。"},
            {"role": "user", "content": f"转换以下歌词(仅输出英文描写):\n{lyrics}"}
        ],
        temperature=0.7,
        max_tokens=300
    )
    return response.choices[0].message.content

# Gradio界面
with gr.Blocks(title="歌词转风景描写", theme=gr.themes.Soft()) as app:
    gr.Markdown("## 🌿 中文歌词转英文风景描写")
    with gr.Row():
        with gr.Column():
            input_text = gr.Textbox(
                label="输入中文歌词",
                placeholder="例:晚风吹来多么清凉...",
                lines=5
            )
            btn = gr.Button("生成", variant="primary")
        with gr.Column():
            output_text = gr.Textbox(
                label="英文风景描写",
                lines=8,
                interactive=False
            )
    
    # 示例数据
    examples = gr.Examples(
        examples=[
            ["对空气不停念你的名字"],
            ["会不会让你我重来一次"]
        ],
        inputs=[input_text],
        label="点击试试示例歌词"
    )
    
    btn.click(
        fn=generate_scenery,
        inputs=input_text,
        outputs=output_text
    )

app.launch(share = True)