Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,14 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# 加载 CodeGen 模型
|
| 5 |
-
code_generator = pipeline('text-generation', model='Salesforce/
|
| 6 |
|
| 7 |
def generate_code(prompt):
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# 创建 Gradio 接口
|
| 11 |
-
iface = gr.Interface(fn=generate_code, inputs="text", outputs="text"
|
| 12 |
-
|
|
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# 加载 CodeGen 模型
|
| 5 |
+
code_generator = pipeline('text-generation', model='Salesforce/codegen-350M-multi') # 确保模型名称正确
|
| 6 |
|
| 7 |
def generate_code(prompt):
|
| 8 |
+
# 设置合理的 max_length
|
| 9 |
+
result = code_generator(prompt, max_length=150, truncation=True) # 使用合理的 max_length
|
| 10 |
+
return result[0]['generated_text']
|
| 11 |
|
| 12 |
# 创建 Gradio 接口
|
| 13 |
+
iface = gr.Interface(fn=generate_code, inputs="text", outputs="text", title="Code Generator",
|
| 14 |
+
description="输入您的代码提示,生成代码片段。")
|
| 15 |
+
iface.launch(share=True) # 设置为 True 以创建公共链接
|