Spaces:
Sleeping
Sleeping
Create llm.py
Browse files
llm.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# **加载 Hugging Face GPT-Neo 模型**
|
| 5 |
+
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B')
|
| 6 |
+
|
| 7 |
+
# **LLM 处理用户输入,解析预测所需的特征**
|
| 8 |
+
def chat_with_llm(user_input):
|
| 9 |
+
prompt = f"请从以下问题中提取出预测所需的参数(年份、期号、中奖号码等):'{user_input}'"
|
| 10 |
+
|
| 11 |
+
# 通过 GPT-Neo 生成对话回复
|
| 12 |
+
response = generator(prompt, max_length=100, num_return_sequences=1)
|
| 13 |
+
extracted_text = response[0]['generated_text']
|
| 14 |
+
|
| 15 |
+
return extracted_text
|
| 16 |
+
|
| 17 |
+
# **Gradio API 服务器**
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=chat_with_llm,
|
| 20 |
+
inputs=gr.Textbox(label="请输入问题或期号信息"),
|
| 21 |
+
outputs="text",
|
| 22 |
+
title="大语言模型 API",
|
| 23 |
+
description="解析用户输入,提取预测所需的特征"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# **启动 API 服务器**
|
| 27 |
+
iface.launch(share=True)
|