Spaces:
Runtime error
Runtime error
File size: 617 Bytes
1b97558 ac8ae0a 1b97558 ad1ee37 91c8167 6b90c39 ad1ee37 |
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 |
import openai
import os
import gradio as gr
openai.api_key = os.environ.get("OPENAI_API_KEY")
openai.api_base = "https://api.fe8.cn/v1"
def generate_text(prefix: str, suffix: str) -> str:
response = openai.Completion.create(
model="text-davinci-003",
prompt=prefix,
suffix=suffix,
max_tokens=1024,
)
return response["choices"][0]["text"]
# 定义Gradio接口
iface = gr.Interface(
fn=generate_text,
inputs=[gr.Textbox(lines=10, label="Prefix"),
gr.Textbox(lines=10, label="Suffix")],
outputs=gr.Textbox(),
)
# 启动Gradio接口
iface.launch()
|