yxccai commited on
Commit
98cad20
·
verified ·
1 Parent(s): fdcf53f

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -45
app.py DELETED
@@ -1,45 +0,0 @@
1
- import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
- import torch
4
-
5
- model_name = "yxccai/text-style-converter"
6
-
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
-
9
- model = AutoModelForCausalLM.from_pretrained(
10
- model_name,
11
- torch_dtype=torch.float32,
12
- device_map="auto",
13
- low_cpu_mem_usage=True
14
- )
15
-
16
- def convert_style(input_text):
17
- prompt = f"""以下是一个文本风格转换任务,请将书面化、技术性的输入文本转换为自然、口语化的表达方式。
18
-
19
- ### 输入文本:
20
- {input_text}
21
-
22
- ### 输出文本:
23
- """
24
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
25
- outputs = model.generate(
26
- **inputs,
27
- max_new_tokens=300,
28
- temperature=0.7,
29
- do_sample=True,
30
- pad_token_id=tokenizer.eos_token_id
31
- )
32
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
33
- if "### 输出文本:" in response:
34
- return response.split("### 输出文本:")[-1].strip()
35
- return response.strip()
36
-
37
- iface = gr.Interface(
38
- fn=convert_style,
39
- inputs=gr.Textbox(label="输入书面化技术性文本"),
40
- outputs=gr.Textbox(label="口语化转换结果"),
41
- title="中文文本风格转换器",
42
- description="将正式、技术性文本转换为自然、口语化表达的语言风格转换模型。"
43
- )
44
-
45
- iface.launch()