Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# **加载 Hugging Face GPT-Neo 模型** | |
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B') | |
# **LLM 处理用户输入,解析预测所需的特征** | |
def chat_with_llm(user_input): | |
prompt = f"请从以下问题中提取出预测所需的参数(年份、期号、中奖号码等):'{user_input}'" | |
# 通过 GPT-Neo 生成对话回复 | |
response = generator(prompt, max_length=100, num_return_sequences=1) | |
extracted_text = response[0]['generated_text'] | |
return extracted_text | |
# **Gradio API 服务器** | |
iface = gr.Interface( | |
fn=chat_with_llm, | |
inputs=gr.Textbox(label="请输入问题或期号信息"), | |
outputs="text", | |
title="大语言模型 API", | |
description="解析用户输入,提取预测所需的特征" | |
) | |
# **启动 API 服务器** | |
iface.launch(share=True) | |