Update main.py
Browse files
main.py
CHANGED
@@ -1,20 +1,19 @@
|
|
1 |
-
|
2 |
-
from fastapi.staticfiles import StaticFiles
|
3 |
-
from fastapi.responses import FileResponse
|
4 |
-
|
5 |
from transformers import pipeline
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
output
|
14 |
-
return {"output": output[0]["generated_text"]}
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# 初始化pipeline
|
5 |
+
pipe_gpt = pipeline("text-generation", model="FreedomIntelligence/Apollo-2B", trust_remote_code=True)
|
|
|
6 |
|
7 |
+
def generate_text(input_text):
|
8 |
+
output = pipe_gpt(input_text, max_length=500) # 调整max_length来控制生成文本的长度
|
9 |
+
return output[0]["generated_text"]
|
|
|
10 |
|
11 |
+
# 创建Gradio界面
|
12 |
+
iface = gr.Interface(fn=generate_text,
|
13 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder="Type your prompt here..."),
|
14 |
+
outputs="text",
|
15 |
+
title="Text Generation with Apollo-2B",
|
16 |
+
description="Enter some text to see how Apollo-2B continues it.")
|
17 |
|
18 |
+
# 运行Gradio应用
|
19 |
+
iface.launch()
|
|