nchen909 commited on
Commit
00d6742
1 Parent(s): 70812f9

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -15
main.py CHANGED
@@ -1,20 +1,19 @@
1
- from fastapi import FastAPI
2
- from fastapi.staticfiles import StaticFiles
3
- from fastapi.responses import FileResponse
4
-
5
  from transformers import pipeline
6
 
7
- app = FastAPI()
8
-
9
- pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
10
 
11
- @app.get("/infer_t5")
12
- def t5(input):
13
- output = pipe_flan(input)
14
- return {"output": output[0]["generated_text"]}
15
 
16
- app.mount("/", StaticFiles(directory="static", html=True), name="static")
 
 
 
 
 
17
 
18
- @app.get("/")
19
- def index() -> FileResponse:
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()