Download app.py from Ankush05/Code4: direct link, hf CLI and curl.
- Browser
- Download file 538 Bytes
-
https://huggingface.co/spaces/Ankush05/Code4/resolve/main/app.py
- Command line
-
hf download hf://spaces/Ankush05/Code4/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Ankush05/Code4/resolve/main/app.py
538 Bytes
| import streamlit as st | |
| from pymongo import MongoClient | |
| import os | |
| from transformers import pipeline | |
| uri = os.environ["MONGO_CONNECTION_STRING"] | |
| client = MongoClient(uri, tlsCertificateKeyFile="database/cert.pem") | |
| db = client["testing"] | |
| col = db["something"] | |
| qna = pipeline("question-answering") | |
| with open("knowledge.txt", "r") as file: | |
| data = file.read() | |
| knowledge = data | |
| if query := st.chat_input("Question: "): | |
| ans = qna(question=query, context=knowledge) | |
| with st.chat_message("User"): | |
| st.write(ans["answer"]) | |