diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ff0fd90 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +**/__pycache__/ \ No newline at end of file diff --git a/api/legal_notice.docx b/api/legal_notice.docx deleted file mode 100644 index ba3816e..0000000 Binary files a/api/legal_notice.docx and /dev/null differ diff --git a/api/new.docx b/api/new.docx deleted file mode 100644 index 334a8ec..0000000 Binary files a/api/new.docx and /dev/null differ diff --git a/document_maker/document_maker.py b/document_maker/document_maker.py index 76fc45c..5e69edf 100644 --- a/document_maker/document_maker.py +++ b/document_maker/document_maker.py @@ -1,33 +1,26 @@ -# from docx import Document -# import os +from docx import Document from open_ai.openai_api import OpenAI - -#document_path = os.path.join('.', 'legal_notice_template.docx') -#path_of_template = './legal_notice_template.docx' -#dev-> TODO: What if any point is incomplete? +import sys class DocumentMaker: - #initialize path def __init__(self, path): - #self.path = path self.document = Document(path) - #change after database allotment - self.new_path = 'legal_notice.docx' + self.new_path = 'legal_notice_new.docx' - #save function def save(self): self.document.save(self.new_path) - def replace_common(self, search_text, replace_text): for paragraph in self.document.paragraphs: for run in paragraph.runs: if search_text in run.text: if search_text == "defect_des": - run.text = OpenAI().get_response(replace_text) + # run.text = OpenAI().get_response(replace_text) + run.text = "gg" break if search_text == "name_of_company": - run.text = replace_text.upper() + # run.text = replace_text.upper() + run.text = "gg" break run.text = replace_text self.save() diff --git a/document_maker/legal_notice_template.docx b/document_maker/legal_notice_template.docx deleted file mode 100644 index a997b93..0000000 Binary files a/document_maker/legal_notice_template.docx and /dev/null differ diff --git a/document_maker/test.docx b/document_maker/test.docx deleted file mode 100644 index 75ac435..0000000 Binary files a/document_maker/test.docx and /dev/null differ diff --git a/legal_notice_new.docx b/legal_notice_new.docx new file mode 100644 index 0000000..c240ac9 Binary files /dev/null and b/legal_notice_new.docx differ diff --git a/legal_notice_template.docx b/legal_notice_template.docx new file mode 100644 index 0000000..a0c42c8 Binary files /dev/null and b/legal_notice_template.docx differ diff --git a/api/api.py b/main.py similarity index 59% rename from api/api.py rename to main.py index 145aa2c..3db6534 100644 --- a/api/api.py +++ b/main.py @@ -6,12 +6,11 @@ from fastapi.responses import FileResponse from document_maker.document_maker import DocumentMaker -path_of_template = "../document_maker/legal_notice_template.docx" +path_of_template = "legal_notice_template.docx" def get_document_maker(): return DocumentMaker(path_of_template) - app = FastAPI() # Allow all origins, methods, and headers. Adjust these settings based on your needs. @@ -32,18 +31,6 @@ def get_document_maker(): async def read_root(): return {"Hello": "World"} -# { -# "name_of_company":"amazon", -# "name_of_entity":"Mr. Jeff Bezos", -# "address_of_entity":"6th & 7th Floor, Ambience Corporate Office Tower-II, Ambience Tower, Ambience Island, Sector 24, Gurugram, Haryana 122002", -# "date_of_rec":"16/02/2024", -# "amount_of_rec":"5000", -# "defect_des": "I have taken the cultfit play pass member ship which charged me around 10000 rs for 3 months. In this memebership I was allowed to play in any of their play centers. At the time of memebership I was using their service for sector 23 which have 3 facaliteis of sports (incl. Badminton, Table Tennis and Lawn Tennis) After having there for around 3 weeks they are shutting down this place due to some reason. When I sad them for the refund the remaining amount they said you can use the service that is available in othr centere which is very far from my current residence. They said that the amound is not refundable.", -# "amount_to_get":"5000", -# "contact_of_user":"+91-888-888-xxxx", -# "email_of_user":"mayanksolanki2023@gmail.com" -# } - #post route for fetching form data @app.post("/process_json_data") @@ -60,4 +47,12 @@ def process_json_data(json_data: dict = Body(...), document_maker: DocumentMaker document_maker.replace_common("email_of_user",json_data.get("email_of_user")) - return FileResponse('./legal_notice.docx', filename='legal_notice.docx') \ No newline at end of file + return FileResponse('./legal_notice_new.docx', filename='legal_notice.docx') + + + + + + + + diff --git a/open_ai/openai_api.py b/open_ai/openai_api.py index 799ae87..5949899 100644 --- a/open_ai/openai_api.py +++ b/open_ai/openai_api.py @@ -4,11 +4,7 @@ load_dotenv() client = OpenAI() - -# A class to handle the openai api class OpenAI: - - #additional code def __init__(self): self.api_key = os.getenv("OPENAI_API_KEY") @@ -24,5 +20,4 @@ def get_response(self, message): ) return str(completion.choices[0].message.content) - #print(type(OpenAI().get_response("I have taken the cultfit play pass member ship which charged me around 10000 rs for 3 months. In this memebership I was allowed to play in any of their play centers. At the time of memebership I was using their service for sector 23 which have 3 facaliteis of sports (incl. Badminton, Table Tennis and Lawn Tennis) After having there for around 3 weeks they are shutting down this place due to some reason. When I sad them for the refund the remaining amount they said you can use the service that is available in othr centere which is very far from my current residence. They said that the amound is not refundable."))) diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..8766592 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +1. Check for the supported docx format before running diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..83a3688 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +fastapi +openai +python-dotenv +python-docx +uvicorn[standard] \ No newline at end of file