HuggingFace
关联:用 Ollama 在本机部署开源的LLM
Huggingface 需要科学上网,但是暂时可以使用镜像网站 hf-mirror
参照官方视频教程
HF_ENDPOINT=https://hf-mirror.com python your_script.py
已有许多 scRNA-seq 应用,比如说 Cell2Sentence - Tutorials 可从 cell_sentences 生成逼真细胞 (expression)
使用
- 通过关键词/标签等筛选模型,模型运行内存大约需要 1.2 倍的 xx_model.bin (Trained Weights)
- 访问 Spaces 空间,在线查看模型使用效果 --- 目前国内访问不了,只能自行 Notebook 中 Gradio Deploy
- 点击 Use This Model 按钮,它会展示所需代码,pipeline中 一般同时包含预处理 Processor,直接使用模型即可
Deploy on Huggingface Space
- 左上角 - New Space - SDK(Gradio) - CPU/GPU
- Add file: requirements.txt
transformers
torch
gradio
- Add file: app.py
import gradio as gr
from transformers import pipeline
pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
def launchFn(input):
out = pipe(input)
return out[0]['generated_text']
iface = gr.Interface(fn=launchFn, inputs=gr.Image(type='pil'), outputs="text")
iface.launch() ## share=True 增加生成一个 public url
- 等待Building完成
Use via API
- Space 页面底部,点击 Use via API
- 它会提供 gradio_client 的代码
from gradio_client import Client
client = Client("https://24h-temp-link")
result = client.predict("local_input.png",api_name="/predict")
print(result) ## 假设此处输出是text
也许可以节省一些本地资源?