Aaron Ploetz commited on
Commit
4a1f813
·
1 Parent(s): a26286a

fixing gradio

Browse files
Files changed (2) hide show
  1. app.py +1 -79
  2. requirements.txt +2 -1
app.py CHANGED
@@ -83,8 +83,7 @@ async def generate_embedding(data: Dict[str, Any]):
83
  content={"error": str(ex)}
84
  )
85
 
86
- with gradio.Blocks(title="Multi-Model Text Embeddings", css_path="./style.css") as gradio_app:
87
- gradio.Markdown("# Multi-Model Text Embeddings")
88
  gradio.Markdown("Generate embeddings for your text using the IBM Granite embedding models.")
89
 
90
  # Model selector dropdown (allows custom input)
@@ -109,83 +108,6 @@ with gradio.Blocks(title="Multi-Model Text Embeddings", css_path="./style.css")
109
  submit_btn.click(embed, inputs=[text_input, model_dropdown], outputs=output, api_name="predict")
110
  text_input.submit(embed, inputs=[text_input, model_dropdown], outputs=output)
111
 
112
- # Add API usage guide
113
- gradio.Markdown("## API Usage")
114
- gradio.Markdown("""
115
- You can use this API in two ways: via the direct FastAPI endpoint or through Gradio clients.
116
-
117
- ### List Available Models
118
- ```bash
119
- curl https://aploetz-granite-embeddings.hf.space/models
120
- ```
121
-
122
- ### Direct API Endpoint (No Queue!)
123
- ```bash
124
- # Default model (nomic-ai/nomic-embed-text-v1.5)
125
- curl -X POST https://ipepe-nomic-embeddings.hf.space/embed \
126
- -H "Content-Type: application/json" \
127
- -d '{"text": "Your text to embed goes here"}'
128
-
129
- # With predefined model (trust_remote_code allowed)
130
- curl -X POST https://ipepe-nomic-embeddings.hf.space/embed \
131
- -H "Content-Type: application/json" \
132
- -d '{"text": "Your text to embed goes here", "model": "sentence-transformers/all-MiniLM-L6-v2"}'
133
-
134
- # With any Hugging Face model (trust_remote_code=False for security)
135
- curl -X POST https://ipepe-nomic-embeddings.hf.space/embed \
136
- -H "Content-Type: application/json" \
137
- -d '{"text": "Your text to embed goes here", "model": "intfloat/e5-base-v2"}'
138
- ```
139
-
140
- Response format:
141
- ```json
142
- {
143
- "embedding": [0.123, -0.456, ...],
144
- "dim": 384,
145
- "model": "sentence-transformers/all-MiniLM-L6-v2",
146
- "trust_remote_code": false,
147
- "predefined": true
148
- }
149
- ```
150
-
151
- ### Python Example (Direct API)
152
- ```python
153
- import requests
154
-
155
- # List available models
156
- models = requests.get("https://ipepe-nomic-embeddings.hf.space/models").json()
157
- print(models["models"])
158
-
159
- # Generate embedding with specific model
160
- response = requests.post(
161
- "https://ipepe-nomic-embeddings.hf.space/embed",
162
- json={
163
- "text": "Your text to embed goes here",
164
- "model": "BAAI/bge-small-en-v1.5"
165
- }
166
- )
167
- result = response.json()
168
- embedding = result["embedding"]
169
- ```
170
-
171
- ### Python Example (Gradio Client)
172
- ```python
173
- from gradio_client import Client
174
-
175
- client = Client("ipepe/nomic-embeddings")
176
- result = client.predict(
177
- "Your text to embed goes here",
178
- "nomic-ai/nomic-embed-text-v1.5", # model selection
179
- api_name="/predict"
180
- )
181
- print(result) # Returns the embedding array
182
- ```
183
-
184
- ### Available Models
185
- - `ibm-granite/granite-embedding-30m-english` - IBM Granite 30M English embedding model
186
- - `ibm-granite/granite-embedding-278m-multilingual` - IBM Granite 278M multilingual embedding model
187
- """)
188
-
189
  if __name__ == '__main__':
190
  # Mount FastAPI app to Gradio
191
  gradio_app = gradio.mount_gradio_app(app, gradio_app, path="/")
 
83
  content={"error": str(ex)}
84
  )
85
 
86
+ with gradio.Blocks(title="Aaron's Granite Text Embeddings service") as gradio_app:
 
87
  gradio.Markdown("Generate embeddings for your text using the IBM Granite embedding models.")
88
 
89
  # Model selector dropdown (allows custom input)
 
108
  submit_btn.click(embed, inputs=[text_input, model_dropdown], outputs=output, api_name="predict")
109
  text_input.submit(embed, inputs=[text_input, model_dropdown], outputs=output)
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  if __name__ == '__main__':
112
  # Mount FastAPI app to Gradio
113
  gradio_app = gradio.mount_gradio_app(app, gradio_app, path="/")
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  sentence_transformers
2
  fastapi
3
- uvicorn
 
 
1
  sentence_transformers
2
  fastapi
3
+ uvicorn
4
+ gradio