Spaces:
Runtime error
Runtime error
wip
Browse files- README.md +6 -5
- app.py +37 -0
- requirements.txt +4 -0
README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
---
|
| 2 |
title: Opensearchspace
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Opensearchspace
|
| 3 |
+
emoji: ⚡
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.3.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
+
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from autogluon.multimodal import MultiModalPredictor
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def text_embedding(query: str):
|
| 6 |
+
model_name = "sentence-transformers/all-MiniLM-L6-v2"
|
| 7 |
+
|
| 8 |
+
predictor = MultiModalPredictor(
|
| 9 |
+
pipeline="feature_extraction",
|
| 10 |
+
hyperparameters={
|
| 11 |
+
"model.hf_text.checkpoint_name": model_name
|
| 12 |
+
}
|
| 13 |
+
)
|
| 14 |
+
query_embedding = predictor.extract_embedding([query])
|
| 15 |
+
return query_embedding["0"]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def main():
|
| 19 |
+
with gr.Blocks(title="OpenSearch Demo") as demo:
|
| 20 |
+
gr.Markdown("# Text Embedding for Search Queries")
|
| 21 |
+
gr.Markdown("Ask an open question!")
|
| 22 |
+
with gr.Row():
|
| 23 |
+
inp = gr.Textbox(show_label=False)
|
| 24 |
+
with gr.Row():
|
| 25 |
+
btn = gr.Button("Generate Embedding")
|
| 26 |
+
with gr.Row():
|
| 27 |
+
out = gr.DataFrame(label="Embedding", show_label=True)
|
| 28 |
+
|
| 29 |
+
btn.click(fn=text_embedding, inputs=inp, outputs=out)
|
| 30 |
+
|
| 31 |
+
demo.launch()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
main()
|
| 36 |
+
|
| 37 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
wheel
|
| 3 |
+
setuptools
|
| 4 |
+
git+https://github.com/awslabs/autogluon.git@master#subdirectory=autogluon
|