Added v2 Code to tree main
Browse files- app.py +9 -6
- requirements.txt +6 -6
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
from langchain_community.vectorstores import FAISS
|
4 |
-
from
|
5 |
from langchain.prompts import PromptTemplate
|
6 |
from langchain_together import Together
|
7 |
|
@@ -31,7 +31,7 @@ ANSWER:
|
|
31 |
prompt = PromptTemplate(template=prompt_template, input_variables=['context', 'question', 'chat_history'])
|
32 |
|
33 |
# Set up Together API
|
34 |
-
TOGETHER_AI_API = "
|
35 |
|
36 |
llm = Together(
|
37 |
model="mistralai/Mistral-7B-Instruct-v0.2",
|
@@ -41,7 +41,7 @@ llm = Together(
|
|
41 |
)
|
42 |
|
43 |
# Create a function to process user input and generate responses
|
44 |
-
def ask_question(user_question):
|
45 |
# Retrieve relevant documents
|
46 |
context_docs = db_retriever.get_relevant_documents(user_question)
|
47 |
|
@@ -52,7 +52,7 @@ def ask_question(user_question):
|
|
52 |
input_data = {
|
53 |
"context": context,
|
54 |
"question": user_question,
|
55 |
-
"chat_history":
|
56 |
}
|
57 |
|
58 |
# Generate an answer
|
@@ -63,7 +63,10 @@ def ask_question(user_question):
|
|
63 |
# Set up Gradio interface
|
64 |
iface = gr.Interface(
|
65 |
fn=ask_question,
|
66 |
-
inputs=
|
|
|
|
|
|
|
67 |
outputs="text",
|
68 |
title="Legal Chatbot",
|
69 |
description="Ask questions about the Indian Penal Code."
|
@@ -71,4 +74,4 @@ iface = gr.Interface(
|
|
71 |
|
72 |
# Launch the Gradio app
|
73 |
if __name__ == "__main__":
|
74 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
from langchain_community.vectorstores import FAISS
|
4 |
+
from langchain_huggingface import HuggingFaceEmbeddings # Updated import
|
5 |
from langchain.prompts import PromptTemplate
|
6 |
from langchain_together import Together
|
7 |
|
|
|
31 |
prompt = PromptTemplate(template=prompt_template, input_variables=['context', 'question', 'chat_history'])
|
32 |
|
33 |
# Set up Together API
|
34 |
+
TOGETHER_AI_API = "your_together_api_key" # Use a secure method to store and retrieve your API key
|
35 |
|
36 |
llm = Together(
|
37 |
model="mistralai/Mistral-7B-Instruct-v0.2",
|
|
|
41 |
)
|
42 |
|
43 |
# Create a function to process user input and generate responses
|
44 |
+
def ask_question(user_question, chat_history=""):
|
45 |
# Retrieve relevant documents
|
46 |
context_docs = db_retriever.get_relevant_documents(user_question)
|
47 |
|
|
|
52 |
input_data = {
|
53 |
"context": context,
|
54 |
"question": user_question,
|
55 |
+
"chat_history": chat_history # Use provided chat history
|
56 |
}
|
57 |
|
58 |
# Generate an answer
|
|
|
63 |
# Set up Gradio interface
|
64 |
iface = gr.Interface(
|
65 |
fn=ask_question,
|
66 |
+
inputs=[
|
67 |
+
gr.Textbox(label="Ask a Question", placeholder="Type your question here..."),
|
68 |
+
gr.Textbox(label="Chat History (Optional)", placeholder="Type chat history here...", lines=2) # Added chat history input
|
69 |
+
],
|
70 |
outputs="text",
|
71 |
title="Legal Chatbot",
|
72 |
description="Ask questions about the Indian Penal Code."
|
|
|
74 |
|
75 |
# Launch the Gradio app
|
76 |
if __name__ == "__main__":
|
77 |
+
iface.launch()
|
requirements.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
|
|
|
|
1 |
langchain
|
2 |
-
|
3 |
-
together
|
4 |
-
transformers
|
5 |
langchain-community
|
6 |
langchain-together
|
|
|
|
|
7 |
einops
|
8 |
-
PyPDF2
|
9 |
-
huggingface-hub
|
10 |
-
gradio
|
|
|
1 |
+
gradio
|
2 |
+
huggingface_hub
|
3 |
langchain
|
4 |
+
langchain-huggingface # New package for HuggingFaceEmbeddings
|
|
|
|
|
5 |
langchain-community
|
6 |
langchain-together
|
7 |
+
faiss-cpu
|
8 |
+
sentence-transformers
|
9 |
einops
|
10 |
+
PyPDF2
|
|
|
|