Spaces:
Runtime error
Runtime error
Download app.py from dbhfesknfjesfb/firstapp: direct link, hf CLI and curl.
- Browser
- Download file 675 Bytes
-
https://huggingface.co/spaces/dbhfesknfjesfb/firstapp/resolve/main/app.py
- Command line
-
hf download hf://spaces/dbhfesknfjesfb/firstapp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/dbhfesknfjesfb/firstapp/resolve/main/app.py
675 Bytes
| import gradio as gr | |
| from sentence_transformers import SentenceTransformer, util | |
| import pickle | |
| # Load corpus and embeddings | |
| with open("data/corpus.pkl", "rb") as f: | |
| corpus = pickle.load(f) | |
| with open("data/embeddings.pkl", "rb") as f: | |
| corpus_embeddings = pickle.load(f) | |
| # Load sentence transformer model | |
| model = SentenceTransformer('all-MiniLM-L6-v2') | |
| def chat(query): | |
| query_emb = model.encode(query, convert_to_tensor=True) | |
| hits = util.semantic_search(query_emb, corpus_embeddings, top_k=1) | |
| answer = corpus[hits[0][0]['corpus_id']] | |
| return answer | |
| iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Semantic Chatbot") | |
| iface.launch() | |