Spaces:
Runtime error
Runtime error
Download app.py from cuiconnect/backend: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/spaces/cuiconnect/backend/resolve/main/app.py
- Command line
-
hf download hf://spaces/cuiconnect/backend/app.py
-
curl -L -o app.py https://huggingface.co/spaces/cuiconnect/backend/resolve/main/app.py
1.81 kB
| import space_credentials # noqa: F401 — sets HF hub env before embeddings load | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from langchain_groq import ChatGroq | |
| from langchain_community.embeddings import HuggingFaceBgeEmbeddings | |
| from chatbot import Comsatsbot | |
| from database import admins_collection, chats_collection, users_collection | |
| from routes import admin, chathistory, query, users | |
| app = FastAPI( | |
| swagger_ui_parameters={"persistAuthorization": True}, | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=False, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| model_name = "BAAI/bge-small-en" | |
| model_kwargs = {"device": "cpu"} | |
| encode_kwargs = {"normalize_embeddings": True} | |
| hf = HuggingFaceBgeEmbeddings( | |
| model_name=model_name, | |
| model_kwargs=model_kwargs, | |
| encode_kwargs=encode_kwargs, | |
| ) | |
| api_keys = [ | |
| "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", | |
| "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", | |
| "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", | |
| "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", | |
| ] | |
| gemini_api_keys = [ | |
| "AIzaSyD6dGpppzVq4--EdI3aCAWtgSyHygV_VnA", | |
| "AIzaSyAhkeFXxdqY8SGdE7_8doyFfwIABzVwoF4", | |
| ] | |
| llm = ChatGroq( | |
| temperature=0, | |
| groq_api_key=api_keys[2], | |
| model_name="llama3-70b-8192", | |
| ) | |
| paths = ["FYP Supervisor Feedback.csv", "urdu_data.csv", "english_data.csv", "csvv.csv"] | |
| chatbot = Comsatsbot(hf, llm, api_keys, chats_collection, paths, gemini_api_keys) | |
| app.state.chatbot = chatbot | |
| app.state.users_collection = users_collection | |
| app.state.admins_collection = admins_collection | |
| app.include_router(admin.router) | |
| app.include_router(users.router) | |
| app.include_router(query.router) | |
| app.include_router(chathistory.router) | |