Spaces:
Running
Running
| from typing import List | |
| import gradio as gr | |
| from sentence_transformers import SentenceTransformer | |
| model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5", trust_remote_code=True, device='cpu') | |
| def embed(document: str): | |
| return model.encode(document) | |
| with gr.Blocks(title="Nomic Text Embeddings") as app: | |
| gr.Markdown("# Nomic Text Embeddings v1.5") | |
| gr.Markdown("Generate embeddings for your text using the nomic-embed-text-v1.5 model.") | |
| # Create an input text box | |
| text_input = gr.Textbox(label="Enter text to embed", placeholder="Type or paste your text here...") | |
| # Create an output component to display the embedding | |
| output = gr.JSON(label="Text Embedding") | |
| # When the input text is submitted, call the embedding function and display the output | |
| text_input.submit(embed, inputs=text_input, outputs=output) | |
| # Add API usage guide | |
| gr.Markdown("## API Usage with cURL") | |
| gr.Markdown(""" | |
| You can use this API programmatically with cURL. Here's how: | |
| ```bash | |
| curl -X POST https://ipepe-nomic-embeddings.hf.space/run/predict \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "data": ["Your text to embed goes here"] | |
| }' | |
| ``` | |
| The response will be in JSON format: | |
| ```json | |
| { | |
| "data": [[0.123, -0.456, 0.789, ...]], | |
| "duration": 0.123 | |
| } | |
| ``` | |
| Replace `https://ipepe-nomic-embeddings.hf.space` with your actual Space URL. | |
| """) | |
| if __name__ == '__main__': | |
| app.queue().launch(server_name="0.0.0.0", show_error=True, server_port=7860) |