LalitMahale commited on
Commit
9322f35
·
1 Parent(s): cbc2cdd
Files changed (4) hide show
  1. app.py +56 -9
  2. process.py +32 -0
  3. requirements.txt +2 -1
  4. text.py +2 -0
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, HTTPException,UploadFile,File
2
  from pydantic import BaseModel
3
  from deep_translator import GoogleTranslator
4
  from fastapi.responses import JSONResponse
@@ -8,6 +8,8 @@ from main import process,audio_process
8
  from dotenv import load_dotenv
9
  import base64
10
  from pathlib import Path
 
 
11
  load_dotenv()
12
  # Create the FastAPI app instance
13
  os.makedirs("/tmp/huggingface_cache", exist_ok=True)
@@ -23,11 +25,24 @@ app.add_middleware(
23
  allow_methods=["*"],
24
  allow_headers=["*"],
25
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  # Root endpoint
28
  @app.get("/")
29
  async def home():
30
- return {"message": "Testing_api"}
31
 
32
  # Token verification function
33
  def verify_token(token: str):
@@ -45,14 +60,27 @@ async def translate(text: str = "", token: str = ""):
45
 
46
  return {"result": result}
47
 
48
- @app.get("/chatbot")
49
- async def chatbot(text: str = "", token: str = ""):
50
- if not text or not token:
 
 
 
51
  raise HTTPException(status_code=400, detail="No text provided")
52
- verify_token(token)
53
- print("User_input :- ",text)
54
- result = process(user_query=text)
55
- return {"result": result}
 
 
 
 
 
 
 
 
 
 
56
 
57
  @app.post("/audio_chat")
58
  async def audio_chat(audio: UploadFile = File(...), token: str = ""):
@@ -95,3 +123,22 @@ async def upload_base64(file_data: FileUploadRequest):
95
 
96
  except Exception as e:
97
  raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException,UploadFile,File,Request
2
  from pydantic import BaseModel
3
  from deep_translator import GoogleTranslator
4
  from fastapi.responses import JSONResponse
 
8
  from dotenv import load_dotenv
9
  import base64
10
  from pathlib import Path
11
+ from process import Response
12
+ import uuid
13
  load_dotenv()
14
  # Create the FastAPI app instance
15
  os.makedirs("/tmp/huggingface_cache", exist_ok=True)
 
25
  allow_methods=["*"],
26
  allow_headers=["*"],
27
  )
28
+ uploaded_docs = {}
29
+
30
+ class UploadRequest(BaseModel):
31
+ filename: str
32
+ filedata: str
33
+
34
+ class ChatRequest(BaseModel):
35
+ session_id: str
36
+ message: str
37
+
38
+ class ChatBot(BaseModel):
39
+ text :str
40
+ token:str
41
 
42
  # Root endpoint
43
  @app.get("/")
44
  async def home():
45
+ return {"message": "Test ok"}
46
 
47
  # Token verification function
48
  def verify_token(token: str):
 
60
 
61
  return {"result": result}
62
 
63
+
64
+ @app.post("/chatbot")
65
+ async def chatbot(req:ChatBot):
66
+ query = req.text
67
+ token = req.token
68
+ if not query or not token:
69
  raise HTTPException(status_code=400, detail="No text provided")
70
+ verify_token(token=token)
71
+ res = Response().chatbot(query=query)
72
+ return {"result":res}
73
+
74
+ # @app.get("/chatbot")
75
+ # async def chatbot(text: str = "", token: str = ""):
76
+ # if not text or not token:
77
+ # raise HTTPException(status_code=400, detail="No text provided")
78
+ # verify_token(token)
79
+ # print("User_input :- ",text)
80
+ # result = process(user_query=text)
81
+ # return {"result": result}
82
+
83
+
84
 
85
  @app.post("/audio_chat")
86
  async def audio_chat(audio: UploadFile = File(...), token: str = ""):
 
123
 
124
  except Exception as e:
125
  raise HTTPException(status_code=500, detail=str(e))
126
+
127
+ @app.post("/upload")
128
+ async def upload_file(req: UploadRequest):
129
+ session_id = str(uuid.uuid4())
130
+ decoded_data = base64.b64decode(req.filedata)
131
+ # Save to disk or memory (or pass to RAG pipeline)
132
+ uploaded_docs[session_id] = decoded_data
133
+ print(session_id)
134
+ return {"success": True, "session_id": session_id}
135
+
136
+ @app.post("/chat")
137
+ async def chat(req: ChatRequest):
138
+ pdf_data = uploaded_docs.get(req.session_id)
139
+ if not pdf_data:
140
+ return {"reply": "Session not found."}
141
+
142
+ # TODO: RAG logic here (e.g., extract text, run through embedding + LLM)
143
+ dummy_answer = f" Nice Mocked answer for: '{req.message}'"
144
+ return {"reply": dummy_answer}
process.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from groq import Groq
2
+ import os
3
+ from text import mytext
4
+ from dotenv import load_dotenv
5
+ load_dotenv()
6
+
7
+ class Response:
8
+ def __init__(self):
9
+ self.client = Groq(api_key = os.getenv("GROQ_API"))
10
+
11
+ def chatbot(self,query:str) -> str:
12
+ try:
13
+ res = self.client.chat.completions.create(
14
+ messages=[
15
+ {"role":"system",
16
+ "content":f"You are a Question answer chatbot. You have to understand the given content based on that provide answer. If don't know tell unable to get details. only give answers do not provide addition text.",
17
+ "role": "user",
18
+ "content": f"Content : {mytext}\n\n Question : what is your name",
19
+ }
20
+ ],
21
+ model="llama-3.3-70b-versatile",
22
+ )
23
+ return res.choices[0].message.content
24
+ except Exception as e:
25
+ print(e)
26
+
27
+
28
+
29
+
30
+ if __name__ == "__main__":
31
+ res = Response().chatbot(query="hi")
32
+ print(res)
requirements.txt CHANGED
@@ -6,4 +6,5 @@ langchain
6
  langchain-community
7
  langchain-google-genai
8
  faster_whisper
9
-
 
 
6
  langchain-community
7
  langchain-google-genai
8
  faster_whisper
9
+ groq==0.28.0
10
+ python-dotenv==1.1.0
text.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ mytext = """"\nLalit Mahale Portfolio and Resume Home\n About\n Interests Skills\n Resume\n Coding Skill\n Portfolio\n Technology\n Contact\nLalit Mahale\nI'm \nAbout\nAI Engineer & Data Science. Birthday: 23 Aug 1997 Phone: +91 8087830153\n City: Jalgaon, Maharashtra\n Age: 27\n Degree: PG Diploma in Artificial IntelligenceInterestsComputer\nReadingWalking\nRunning\nVideo GamingSkills Python Machine Learning Deep Learning Natural Langague Processing GPT 3.5 / GPT 4 LLAMA (llama 2/ llama coder) Gemini Pro / Gemini Vision Pro LLM Gemma LLM Transformers / BERT Lora (LLM finetunning method) Flask / FAST API SciKit Learn TensorFlow NLTK / SpaCy PyTorch Langchain / LLAMA Index FAISS (Facebook AI Semantic Search) Pinecone / Croma DB CrewAI QLora (LLM finetunning method) Resume\nExperienceMachine Learning Engineer\nAkrivia Automation Pvt Ltd\nDec 2023 - Present\nHyderabad, TelanganaMachine Learning Developer\nAssisto Technolog Pvt Ltd\nApril 2023 - Nov 2023\nRemoteAI / ML Developer\nBluehole (OPC) Pvt Ltd\nSep 2022 - Mar 2023\nAhmedabad, Gujarat\nEducationPost Graduate Diploma in Artificial Intelligent \nMar 2022 - SEP 2022 \n74%\nCDAC, Pune\nView\nM.Sc. Physics\n2019 - 2021\n81%\nKBC North Maharashtra University, Jalgaon\nView\nB.Sc. Physics\n2015 - 2018\n70%\nNorth Maharashtra University, Jalgaon\nViewAdditional CertificationDatabricks Generative AI Fundamentals\n25 Feb 2024 \nView\nDatabricks\nPython\n19 Sep 2022 \nView\nhackerrank\nSQL\n04 Nov 2022\nView\nhackerrank\nIntroduction to Natural Language Processing\n28 Nov 2022\nView\nAnalytic Vidya \nAdvanced Computer Vision with OpenCV and Python\n19 June 2022\nView\nmachinelearning.org.in\nPython 101 for Data Science\n14 Aug 2022\nView\nCognitiveClass.ai provided by IBM \nData Visualization With Power BI\nOct 2022\nView\nGreat Learning Coding Skill\n Greeks For GreeksHackerRank\nKaggle\nPortfolioAll\nGenerative AI\nData Science\nNLP\nComputer Vision\nGenerative AI Project\nMedical Report Analyzer\n\nData Science Project\nUber Price Prediction using Multiple Factors\nComputer Vision Project\nVehicle Entry and Exit Management System Using Number Plate Recognition\n\nGenerative AI Project\nPersonal Fitness Bot\n\nData Science Project\nCredit Card Fraud Detection\n\nNLP Project\nConvert Your Text into Speech or PDF to Speech \n\nGenerative AI Project\nDocument summarizer\n\nGenerative AI Project\nRAG Chatbot\n\nGenerative AI Project\nChat With Database\n\nComputer Vision Project\nDog Breed Classification Using CNN and Transfer Learning\n\nData Science\nLoan Prediction Using Machine Learning\n\nData Science\nMultiple Disease Prediction System\n\nNLP Project\nChatbot From Scratch using NLTK and Sklearn\n\nNLP Project\nWhatsApp Chat Sentiment Analysis\n\nComputer Vision Project\nFace Emotion Recognition using PyTorch\nTechnologyPower BI / Tableau\nTableau and Power BI both are among the most popular Business Intelligent platform in the market.Tableau is an excellent data visualization and BI tool used for reporting and analyzing large volumes of data.\nTensorFlow / PyTorch\nTensorFlow and PyTorch are the top libraries of machine learning and developed in Python language. These are open-source neural-network library framework.\nNLTK / SpaCy\nNLTK and spaCy are two of the most popular Natural Language Processing (NLP) libraries available in Python. we can build chatbots, automatic summarizers, and entity extraction engines and many more by using these libraries.\n OpenCv\nOpenCv (Open Source Computer Vision Library) is a library used for computer vision task like a real time video analysis, Image Preprocessing and many more task.\nHTML / CSS\nHTML and CSS are scripting languages used to create a web page and web applications. HTML provides web page structure, whereas CSS is mainly used to control web page styling\nDevOps\nDevOps ( development and operations) is an enterprise software development phrase used to mean a type of agile relationship between development and IT operations.\nContact\nLocation:\n55 Samrat Colony, Jalgaon, Maharashtra, India 425001Email:\[email protected]:\n+91 80878 30153\nLoadingYour message has been sent. Thank you!Send MessageLalit Mahale\nThanks For visit my Portfolio site .\r\n © Copyright Lalit Mahale. All Rights Reserved\r\n \n Chat with Us\nX\nHello! How can I help you today?\n"
2
+ """