Spaces:
Sleeping
Sleeping
# hf的功能 | |
## 文字 | |
https://huggingface.co/docs/huggingface_hub/main/en/guides/inference#run-inference-on-servers | |
from huggingface_hub import InferenceClient | |
messages = [{"role": "user", "content": "中国的首都是哪里?"}] | |
client = InferenceClient("meta-llama/Llama-3.2-11B-Vision-Instruct") | |
client.chat_completion(messages, max_tokens=100) | |
from huggingface_hub import InferenceClient | |
messages = [{"role": "user", "content": "中国的首都是哪里?"}] | |
client = InferenceClient("google/gemma-2-2b-it") | |
client.chat_completion(messages, max_tokens=100) | |
## 图片 | |
> 中文识别不好 | |
from huggingface_hub import InferenceClient | |
client = InferenceClient() | |
image = client.text_to_image("An astronaut riding a horse on the moon.") | |
image.save("/Users/sanbo/Desktop/astronaut.png") # 'image' is a PIL.Image object | |
from huggingface_hub import InferenceClient | |
client = InferenceClient("black-forest-labs/FLUX.1-dev") | |
image = client.text_to_image("一个天上飞的乌龟.") | |
image.save("/Users/sanbo/Desktop/astronaut.png") # 'image' is a PIL.Image object | |
## 视觉问答visual_question_answering | |
from huggingface_hub import InferenceClient | |
client = InferenceClient() | |
client.visual_question_answering( | |
image="https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg", | |
question="What is the animal doing?" | |
) | |
## 翻译 | |
from huggingface_hub import InferenceClient | |
client = InferenceClient() | |
client.translation("My name is Wolfgang and I live in Berlin") | |
'Mein Name ist Wolfgang und ich lebe in Berlin.' | |
client.translation("My name is Wolfgang and I live in Berlin", model="Helsinki-NLP/opus-mt-en-zh") | |
Helsinki-NLP/opus-mt-zh-en | |
### 使用特定模型 | |
client = InferenceClient(model="prompthero/openjourney-v4") | |
client.text_to_image("xxx") | |
方式二 | |
client = InferenceClient() | |
client.text_to_image(..., model="prompthero/openjourney-v4") | |
## 客户端请求 | |
from huggingface_hub import InferenceClient | |
client = InferenceClient() | |
response = client.post(json={"inputs": "An astronaut riding a horse on the moon."}, model="stabilityai/stable-diffusion-2-1") | |
response.content | |
## 支持模型 | |
https://huggingface.co/models?other=conversational&sort=likes | |
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct") | |
client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct") | |
## 支持任务 | |
| 域 | 任务 | 支持 | 文件 | | |
| :--------: | :---------------------------------------------------------------------------: | :---: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | |
| 音频 | [音频分类](https://huggingface.co/tasks/audio-classification) | ✅ | [audio_classification()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.audio_classification) | | |
| 音频 | [音频到音频](https://huggingface.co/tasks/audio-to-audio) | ✅ | [audio_to_audio()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.audio_to_audio) | | |
| | [自动语音识别](https://huggingface.co/tasks/automatic-speech-recognition) | ✅ | [自动语音识别](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.automatic_speech_recognition) | | |
| | [Text-to-Speech](https://huggingface.co/tasks/text-to-speech) | ✅ | [text_to_speech()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.text_to_speech) | | |
| 计算机视觉 | [图像分类](https://huggingface.co/tasks/image-classification) | ✅ | [image_classification()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.image_classification) | | |
| | [图像分割](https://huggingface.co/tasks/image-segmentation) | ✅ | [image_segmentation()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.image_segmentation) | | |
| | [Image-to-Image](https://huggingface.co/tasks/image-to-image) | ✅ | [image_to_image()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.image_to_image) | | |
| | [图像到文本](https://huggingface.co/tasks/image-to-text) | ✅ | [image_to_text()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.image_to_text) | | |
| | [对象检测](https://huggingface.co/tasks/object-detection) | ✅ | [object_detection()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.object_detection) | | |
| | [文字转影像](https://huggingface.co/tasks/text-to-image) | ✅ | [text_to_image()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.text_to_image) | | |
| | [零拍摄图像分类](https://huggingface.co/tasks/zero-shot-image-classification) | ✅ | [zero_shot_image_classification()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.zero_shot_image_classification) | | |
| 多式 | [文档问题存档](https://huggingface.co/tasks/document-question-answering) | ✅ | [document_question_answering()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.document_question_answering) | | |
| | [视觉问题回答](https://huggingface.co/tasks/visual-question-answering) | ✅ | [visual_question_answering()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.visual_question_answering) | | |
| NLP | 会话 | | 已弃用,请使用聊天完成 | | |
| | [聊天完成](https://huggingface.co/tasks/text-generation) | ✅ | [chat_completion()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.chat_completion) | | |
| | [特征提取](https://huggingface.co/tasks/feature-extraction) | ✅ | [feature_extraction()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.feature_extraction) | | |
| | [填充掩膜](https://huggingface.co/tasks/fill-mask) | ✅ | [fill_mask()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.fill_mask) | | |
| | [问答](https://huggingface.co/tasks/question-answering) | ✅ | [question_answering()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.question_answering) | | |
| | [句子相似度](https://huggingface.co/tasks/sentence-similarity) | ✅ | [sentence_similarity()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.sentence_similarity) | | |
| | [总结](https://huggingface.co/tasks/summarization) | ✅ | [summarizing()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.summarization) | | |
| | [表格问题分类](https://huggingface.co/tasks/table-question-answering) | ✅ | [table_question_answering()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.table_question_answering) | | |
| | [文本分类](https://huggingface.co/tasks/text-classification) | ✅ | [text_classification()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.text_classification) | | |
| | [Generation Text一代](https://huggingface.co/tasks/text-generation) | ✅ | [text_generation()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.text_generation) | | |
| | [记号分类](https://huggingface.co/tasks/token-classification) | ✅ | [token_classification()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.token_classification) | | |
| | [翻译](https://huggingface.co/tasks/translation) | ✅ | [translation()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.translation) | | |
| | [零炮分类](https://huggingface.co/tasks/zero-shot-classification) | ✅ | [零炮分类](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.zero_shot_classification) | | |
| 表格 | [表格分类](https://huggingface.co/tasks/tabular-classification) | ✅ | [表分类](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.tabular_classification) | | |
| | [表格回归](https://huggingface.co/tasks/tabular-regression) | ✅ | [table_regression()](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.InferenceClient.tabular_regression) | | |
任务页面: https://huggingface.co/tasks |