Last active
September 25, 2023 06:22
-
-
Save frutik/ab22a4d2f668a58eb01badb113a87f16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from transformers.tools import HfAgent | |
>>> a = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder") | |
>>> text = """Ukraine says Friday's missile strike on the headquarters of Russia's Black Sea fleet in Crimea was timed to coincide with a meeting of naval officials. | |
The fleet, based in the port city of Sevastopol, is seen as the best of Russia's navy. | |
A Ukrainian military source told the BBC that Friday's attack was carried out using Storm Shadow missiles, which are supplied by Britain and France.""" | |
>>> a.run("Can you summarize `text` for me", text=text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://huggingface.co/docs/transformers/tasks/zero_shot_object_detection | |
https://huggingface.co/docs/transformers/tasks/object_detection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://huggingface.co/docs/transformers/tasks/zero_shot_object_detection | |
https://huggingface.co/docs/transformers/tasks/object_detection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from huggingface_hub import InferenceClient | |
>>> client = InferenceClient() | |
>>> image = client.text_to_image("A penguin with chainsaw. klimt style") | |
>>> image.save("astronaut.png") | |
>>> image = client.text_to_image("A penguin with chainsaw. monet style") | |
>>> image.save("astronaut2.png") | |
image = client.text_to_image("A penguin with chainsaw. monet style") | |
image.save("astronaut2.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install huggingface_hub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from huggingface_hub import InferenceClient | |
>>> client = InferenceClient() | |
>>> client.image_to_text("https://assets.webshop.nl/products/Shopping/e46e0ed50ca6a061a4fbb790cf9c742f.300x300.jpeg") | |
'a set of four small cups with different colors' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client.zero_shot_image_classification('https://assets.shops.ae/products/Shopping/9259fb77287d4925f3d3763b85e1bf48.300x300.jpeg', labels=b[0:10]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import pipeline | |
pipe = pipeline("image-classification", model="rizvandwiki/gender-classification") | |
pipe('https://assets.webshop.nl/products/Shopping/f3f97e5bfcc0d8d80229e2dff6dddb90.300x300.jpeg') | |
pipe(["https://assets.webshop.nl/products/Shopping/134aed2f59a9eff753a935738d550b63.300x300.jpeg", "https://assets.webshop.nl/products/Shopping/d3bd90e34b45cecc189a9954ac9dc308.300x300.jpeg"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KeyError: "Unknown task text-to-image, available tasks are ['audio-classification', 'automatic-speech-recognition', 'conversational', 'depth-estimation', 'document-question-answering', 'feature-extraction', 'fill-mask', 'image-classification', 'image-segmentation', 'image-to-text', 'mask-generation', 'ner', 'object-detection', 'question-answering', 'sentiment-analysis', 'summarization', 'table-question-answering', 'text-classification', 'text-generation', 'text-to-audio', 'text-to-speech', 'text2text-generation', 'token-classification', 'translation', 'video-classification', 'visual-question-answering', 'vqa', 'zero-shot-audio-classification', 'zero-shot-classification', 'zero-shot-image-classification', 'zero-shot-object-detection', 'translation_XX_to_YY']" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from transformers import pipeline | |
>>> model_name = "openai/clip-vit-large-patch14-336" | |
>>> classifier = pipeline("zero-shot-image-classification", model = model_name) | |
>>> classifier('https://assets.webshop.nl/products/Shopping/7da005230f6d740348af4d923c1805c6.300x300.jpeg', candidate_labels=['male', 'female', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']) | |
[{'score': 0.7134156823158264, 'label': 'male'}, {'score': 0.12635408341884613, 'label': 'female'}, {'score': 0.02425290271639824, 'label': '4'}, {'score': 0.021945219486951828, 'label': '2'}, {'score': 0.020914090797305107, 'label': '3'}, {'score': 0.01855575293302536, 'label': '5'}, {'score': 0.017798833549022675, 'label': '6'}, {'score': 0.014678528532385826, 'label': '1'}, {'score': 0.012363165616989136, 'label': '7'}, {'score': 0.01090542133897543, 'label': '8'}, {'score': 0.009844750165939331, 'label': '9'}, {'score': 0.00897147785872221, 'label': '10'}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://huggingface.co/docs/transformers/training | |
https://huggingface.co/EZlee/e-commerce-bert-base-multilingual-cased |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment