Spaces:
Paused
Paused
Download app.py from hamxahbhattii/jin-e: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/hamxahbhattii/jin-e/resolve/main/app.py
- Command line
-
hf download hf://spaces/hamxahbhattii/jin-e/app.py
-
curl -L -o app.py https://huggingface.co/spaces/hamxahbhattii/jin-e/resolve/main/app.py
1.17 kB
| from fastapi import FastAPI, HTTPException, Query | |
| # Import the Jine class and other necessary modules | |
| from jine import Jine # Replace 'your_module_name' with the actual module name | |
| from pydantic import BaseModel | |
| # Load your environment variables | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
| DATA_DIRECTORY = os.getenv("DATA_DIRECTORY") | |
| VECTOR_STORE_DIRECTORY = os.getenv("VECTOR_STORE_DIRCTORY") | |
| VECTOR_STORE_CHECK = os.getenv("VECTOR_STORE_CHECK") | |
| DEBUG = os.getenv("DEBUG") | |
| # Initialize Jine | |
| jine = Jine(OPENAI_API_KEY, VECTOR_STORE_DIRECTORY, VECTOR_STORE_CHECK, DATA_DIRECTORY, DEBUG) | |
| jine.load_model() | |
| # Create a FastAPI app | |
| app = FastAPI() | |
| # Define a request model | |
| class ChatRequest(BaseModel): | |
| user_question: str | |
| # Define a response model | |
| class ChatResponse(BaseModel): | |
| user_question: str | |
| chatbot_response: str | |
| # Define the chatbot endpoint | |
| def chat_with_bot(request: ChatRequest): | |
| user_question = request.user_question | |
| chatbot_response = jine.chat(user_question) | |
| return ChatResponse(user_question=user_question, chatbot_response=chatbot_response) | |