Comments (2)
It's about Transformers.js' API spec where you have to pass the labels
at prediction, not model initialization (see https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.ZeroShotClassificationPipeline).
So your code should be modified like this:
from transformers_js import import_transformers_js
import gradio as gr
labels=['politics', 'music','police']
transformers = await import_transformers_js()
pipeline = transformers.pipeline
model_path = 'Xenova/mobilebert-uncased-mnli'
pipe = await pipeline('zero-shot-classification', model_path) # Not here.
async def classify(text):
pred = await pipe(text, labels) # Pass `labels` here.
return pred["scores"]
demo = gr.Interface(classify, "textbox", "textbox")
demo.launch()
from gradio.
I first try to define labels within the pipe at inference (as with "classic" Transformer pipeline). Wasn't working.
Then I tried at model initialization. Wasn't working either as expected.
Seems you have to define them separately from inference call.
It's working now.
Arigato !
from transformers_js import import_transformers_js
import gradio as gr
labels=['politics', 'music','police'] # works
transformers = await import_transformers_js()
pipeline = transformers.pipeline
model_path = 'Xenova/mobilebert-uncased-mnli'
pipe = await pipeline('zero-shot-classification', model_path) # Not here.
# labels=['politics', 'music','police'] # works
async def classify(text):
pred = await pipe(text, labels # Pass `labels` here.
# labels=['politics', 'music','police'] # doesn't work
)
return pred["scores"]
demo = gr.Interface(classify, "textbox", "textbox")
demo.launch()
from gradio.
Related Issues (20)
- Gradio with gunicorn+uvicorn auth, /queue/join 401 Unauthorized randomly HOT 1
- delete_cache not working HOT 2
- `.svg` files cannot be used as avatar_images HOT 5
- <!-- tag=changesets_gradio --> HOT 1
- A syntax error occurred in the viewer console HOT 2
- The autoplay parameter for audio or video does not take effect in Chatbot
- Refresh method for FileExplorer component HOT 1
- Audio component to have events for "loading of audio file complete", especially when loading large audio files HOT 1
- Ensure Button icon looks good when no text is specified HOT 3
- Disable telemetry HOT 2
- Document how to select a directory in `gr.FileExplorer` HOT 9
- Audio streaming not working for large files HOT 3
- ImageEditor's toolbox not show complete HOT 2
- Choice updates to dropdowns are forgotten when component is re-renderred with a key
- ValueError when using gradio components in Chatbot messages and streaming response HOT 1
- Repository too heavy HOT 1
- Warning caused by empty 'for' attribute in BlockLabel (Firefox only)
- ChatInterface type='messages', API still uses tuples format HOT 1
- Hangs at loading shards then get a OOM error. HOT 1
- Certain static files are requested over http (instead of https) behind kubernetes proxy HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gradio.