Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="audio")
|
| 10 |
-
demo.launch(true)
|
| 11 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def load_model():
|
| 4 |
+
# 在这里加载 Hugging Face 模型
|
| 5 |
+
# 比如使用 transformers 库来加载模型
|
| 6 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 7 |
+
model_name = "zeroMN/zeroMN_SHMT"
|
| 8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
return model, tokenizer
|
| 11 |
|
| 12 |
+
def infer(text):
|
| 13 |
+
model, tokenizer = load_model()
|
| 14 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 15 |
+
outputs = model(**inputs)
|
| 16 |
+
# 根据模型输出生成响应
|
| 17 |
+
return f"Predicted response for: {text}"
|
| 18 |
|
| 19 |
+
# 使用 Gradio 创建接口
|
| 20 |
+
gr.Interface(fn=infer, inputs="text", outputs="text").launch()
|
|
|
|
|
|
|
|
|
|
| 21 |
|