ishaan-mital commited on
Commit
1e5cddc
1 Parent(s): 4d82c20

initial commit

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +39 -15
  3. requirements.txt +6 -1
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py CHANGED
@@ -1,27 +1,51 @@
1
  from gradio_client import Client
2
  import gradio as gr
 
 
 
 
 
 
 
 
3
 
4
- chat_client = Client("https://mosaicml-mpt-30b-chat.hf.space/", serialize = False)
5
- retrieval = Client("https://ishaan-mital-ncert-helper-vector-db.hf.space/--replicas/149bg26k5/")
6
 
7
- init_prompt ="## Instruction: You are an AI language model and must return truthful responses as per the information. Do not answer with any information which isn't completely verified and correct. Do not lie. Do not present information where you don't know the answer. Do not include incorrect extra information. Your name is NCERT-Helper. You are a helpful and truthful chatbot. You can help create questions(MCQs) for students in their 11th and 12th standard CBSE Board."
8
- info="Information: \n"
9
- # q_prompt="\n ##Instruction: Please provide an appropriate response to the following in less than 3 lines: \n"
10
- chatbot = [["", None]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  def main(question):
14
  global chatbot
15
- information = retrieval.predict(question, api_name = "/predict")
16
- answer=chat_client.predict(
17
- info +information+question, # str in 'Type an input and press Enter' Textbox component
18
- chatbot,
19
- fn_index=1
20
- )
21
- chatbot = answer[1]
22
- return answer[1][0][1]
23
 
24
  demo = gr.Interface(main, inputs = "text", outputs = "text")
25
 
26
  if __name__ == "__main__":
27
- demo.launch()
 
1
  from gradio_client import Client
2
  import gradio as gr
3
+ import requests
4
+ from langchain.chains import RetrievalQA
5
+ from langchain.vectorstores import Pinecone
6
+ import pinecone
7
+ from langchain.qa import RetrievalQA
8
+ from langchain.vectorstore import vectorstore
9
+ import os
10
+ from langchain.embeddings.huggingface import HuggingFaceEmbeddings
11
 
12
+ API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
13
+ # retrieval = Client("https://ishaan-mital-ncert-helper-vector-db.hf.space/--replicas/149bg26k5/")
14
 
15
+ embed_model_id = 'sentence-transformers/all-MiniLM-L6-v2'
16
+ embed_model = HuggingFaceEmbeddings(
17
+ model_name=embed_model_id,
18
+ )
19
+ pinecone.init(
20
+ api_key=os.environ.get('PINECONE_API_KEY'),
21
+ environment=os.environ.get('PINECONE_ENVIRONMENT')
22
+ )
23
+
24
+ index_name = 'llama-rag'
25
+ index = pinecone.Index(index_name)
26
+ text_field = 'text' # field in metadata that contains text content
27
+
28
+ vectorstore = Pinecone(
29
+ index, embed_model.embed_query, text_field
30
+ )
31
+
32
+ def call_llm_api(input_text):
33
+ headers = {"Authorization": f"Bearer {os.environ.get('API_KEY')}"}
34
+ payload = {"imput": input_text}
35
+ response = requests.post(API_URL, headers=headers, json=payload)
36
+ return response.json() # Adjust as needed based on your API response format
37
+
38
+ rag_pipeline = RetrievalQA.from_chain_type(
39
+ llm=call_llm_api, chain_type='stuff',
40
+ retriever=vectorstore.as_retriever()
41
+ )
42
 
43
 
44
  def main(question):
45
  global chatbot
46
+ return rag_pipeline(question)
 
 
 
 
 
 
 
47
 
48
  demo = gr.Interface(main, inputs = "text", outputs = "text")
49
 
50
  if __name__ == "__main__":
51
+ demo.launch(share=True)
requirements.txt CHANGED
@@ -1,4 +1,9 @@
1
  hugchat
2
  gradio
3
  gradio_client
4
- gtts
 
 
 
 
 
 
1
  hugchat
2
  gradio
3
  gradio_client
4
+ gtts
5
+ pydantic==1.10.9
6
+ langchain
7
+ pinecone-client==2.2.2
8
+ faiss-cpu
9
+ sentence_transformers