|
""" |
|
streamlit run app.py --server.address 0.0.0.0 |
|
""" |
|
|
|
from __future__ import annotations |
|
|
|
import os |
|
from time import time |
|
|
|
import faiss |
|
import pandas as pd |
|
import streamlit as st |
|
from open_clip import create_model_and_transforms |
|
from openai import OpenAI |
|
from qdrant_client import QdrantClient |
|
from qdrant_client.http import models |
|
|
|
if os.getenv("SPACE_ID"): |
|
USE_HF_SPACE = True |
|
os.environ["HF_HOME"] = "/data/.huggingface" |
|
os.environ["HF_DATASETS_CACHE"] = "/data/.huggingface" |
|
else: |
|
USE_HF_SPACE = False |
|
|
|
|
|
os.environ["TOKENIZERS_PARALLELISM"] = "false" |
|
|
|
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY") |
|
QDRANT_API_ENDPOINT = os.environ.get("QDRANT_API_ENDPOINT") |
|
QDRANT_API_KEY = os.environ.get("QDRANT_API_KEY") |
|
|
|
if not QDRANT_API_ENDPOINT or not QDRANT_API_KEY: |
|
raise ValueError("env: QDRANT_API_ENDPOINT or QDRANT_API_KEY is not set.") |
|
|
|
|
|
@st.cache_resource |
|
def get_model_preprocess(): |
|
model, _, preprocess = create_model_and_transforms( |
|
"xlm-roberta-base-ViT-B-32", pretrained="laion5B-s13B-b90k" |
|
) |
|
return model, preprocess |
|
|
|
|
|
@st.cache_resource |
|
def get_qdrant_client(): |
|
qdrant_client = QdrantClient( |
|
url=QDRANT_API_ENDPOINT, |
|
api_key=QDRANT_API_KEY, |
|
) |
|
return qdrant_client |
|
|
|
|
|
def app(): |
|
st.title("secon.dev site search") |
|
|
|
|
|
if __name__ == "__main__": |
|
app() |
|
|