-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e79e7c8
commit 262bd24
Showing
7 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from backend import app | ||
from .Exceptions import * | ||
|
||
from fastapi.responses import JSONResponse | ||
from fastapi.requests import Request | ||
from fastapi import status | ||
|
||
@app.exception_handler(ModelDeployingException) | ||
async def model_deploying_exception_handler(request: Request, exc: ModelDeployingException): | ||
return JSONResponse( | ||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE, | ||
content=repr(exc) | ||
) | ||
|
||
@app.exception_handler(InfoNotProvidedException) | ||
async def info_not_provided_exception_handler(request: Request, exc: InfoNotProvidedException): | ||
return JSONResponse( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
content=repr(exc) | ||
) | ||
|
||
@app.exception_handler(DataNotUploadedException) | ||
async def data_not_uploaded_exception_handler(request: Request, exc: DataNotUploadedException): | ||
return JSONResponse( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
content=repr(exc) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from backend.schemas import FrontendResponseModel | ||
|
||
|
||
class ModelDeployingException(Exception): | ||
def __init__(self, response_result: FrontendResponseModel): | ||
self.response_result = response_result | ||
self.set_status() | ||
super(ModelDeployingException, self).__init__() | ||
|
||
def set_status(self): | ||
self.response_result["status"] = "Error" | ||
self.response_result["message"][0]="Model is deploying. Please try again later." | ||
|
||
def __repr__(self): | ||
return f"exception.ModelDeployingException()" | ||
|
||
|
||
|
||
class InfoNotProvidedException(Exception): | ||
def __init__(self, response_result: FrontendResponseModel, message: str): | ||
self.response_result = response_result | ||
self.message = message | ||
self.set_status() | ||
super(InfoNotProvidedException, self).__init__(message) | ||
|
||
def set_status(self): | ||
self.response_result["status"] = "Error" | ||
self.response_result["message"][0] = "Information not provided." | ||
self.response_result["message"].append(self.message) | ||
|
||
def __repr__(self): | ||
return f"exception.InfoNotProvidedException()" | ||
|
||
|
||
class DataNotUploadedException(Exception): | ||
def __init__(self, response_result: FrontendResponseModel): | ||
self.response_result = response_result | ||
self.set_status() | ||
super(ModelDeployingException, self).__init__() | ||
|
||
def set_status(self): | ||
self.response_result["status"] = "Error" | ||
self.response_result["message"].append( | ||
"Data not uploaded. Please upload a file." | ||
) | ||
|
||
def __repr__(self): | ||
return f"exception.DataNotUploadedException()" | ||
|
||
|
||
class PdfLoaderException(Exception): | ||
def __init__(self, response_result: FrontendResponseModel): | ||
self.response_result = response_result | ||
self.set_status() | ||
super(ModelDeployingException, self).__init__() | ||
|
||
def set_status(self): | ||
self.response_result["status"] = "Error" | ||
self.response_result["message"].append( | ||
"PDF Loader Exception. Please try again." | ||
) | ||
|
||
def __repr__(self): | ||
return f"exception.PdfLoaderException()" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
from typing import List | ||
from pydantic import BaseModel | ||
|
||
|
||
class FrontendResponseModel(BaseModel): | ||
message: str | ||
status: str | ||
message: List[str] | ||
result: dict | ||
|
||
class DataResponseModel(BaseModel): | ||
status: str | ||
message: List[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
streamlit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import streamlit as st | ||
|
||
import requests | ||
|
||
# from studybot import qa_chain | ||
# st.write(qa_chain) | ||
|
||
upload_pdf = st.file_uploader("Upload PDF", type="pdf") | ||
if upload_pdf is not None: | ||
files = {"file": upload_pdf} | ||
response = requests.post("https://hemanthsai7-studybotapi.hf.space/api/upload", files=files) | ||
st.write(response) | ||
|
||
query=st.text_input("Question", key="question") | ||
st.write(st.session_state) | ||
|
||
if st.button("Ask"): | ||
# answer = qa_chain(query) | ||
answer = st.session_state["qa_chain"](query) | ||
answer = requests.post("https://hemanthsai7-studybotapi.hf.space/api/inference", json={"promptMessage": query}).json() | ||
st.write(answer) | ||
# st.session_state["question"] = "" |