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