Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import subprocess
|
|
2 |
subprocess.run('pip install -r requirements.txt', shell = True)
|
3 |
|
4 |
import gradio as gr
|
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
@@ -14,7 +15,8 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
|
|
14 |
from langchain.text_splitter import CharacterTextSplitter
|
15 |
from langchain_core.output_parsers import StrOutputParser
|
16 |
from langchain_core.runnables import RunnablePassthrough
|
17 |
-
from langchain_fireworks import ChatFireworks
|
|
|
18 |
from langchain_community.llms import Ollama
|
19 |
from langchain_core.prompts import ChatPromptTemplate
|
20 |
from rich.console import Console
|
@@ -74,19 +76,19 @@ def ragChain():
|
|
74 |
|
75 |
output: rag chain
|
76 |
"""
|
77 |
-
loader = TextLoader("knowledgeBase.txt")
|
78 |
-
docs = loader.load()
|
79 |
|
80 |
-
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
81 |
-
docs = text_splitter.split_documents(docs)
|
82 |
|
83 |
-
vectorstore = FAISS.
|
84 |
retriever = vectorstore.as_retriever(search_type = "similarity", search_kwargs = {"k": 5})
|
85 |
|
86 |
-
APIKEY = "o7T3gVx9Vt8GSJbLyPV1974vF8LXVp01CWqOkWQuHgoHm07H"
|
87 |
-
os.environ["FIREWORKS_API_KEY"] = APIKEY
|
88 |
|
89 |
-
llm =
|
90 |
|
91 |
prompt = ChatPromptTemplate.from_messages(
|
92 |
[
|
@@ -98,17 +100,17 @@ def ragChain():
|
|
98 |
),
|
99 |
(
|
100 |
"human",
|
101 |
-
"""Provide information about the leaf disease in question in bullet points.
|
102 |
Start your answer by mentioning the disease (if any) or healthy in this format: 'Condition: disease name'.
|
103 |
""",
|
104 |
),
|
105 |
-
|
106 |
("human", "{context}, {question}"),
|
107 |
]
|
108 |
)
|
109 |
|
110 |
rag_chain = (
|
111 |
-
{
|
112 |
"context": retriever,
|
113 |
"question": RunnablePassthrough()
|
114 |
}
|
|
|
2 |
subprocess.run('pip install -r requirements.txt', shell = True)
|
3 |
|
4 |
import gradio as gr
|
5 |
+
import cv2
|
6 |
import os
|
7 |
from PIL import Image
|
8 |
import numpy as np
|
|
|
15 |
from langchain.text_splitter import CharacterTextSplitter
|
16 |
from langchain_core.output_parsers import StrOutputParser
|
17 |
from langchain_core.runnables import RunnablePassthrough
|
18 |
+
#from langchain_fireworks import ChatFireworks
|
19 |
+
from langchain_anthropic import ChatAnthropic
|
20 |
from langchain_community.llms import Ollama
|
21 |
from langchain_core.prompts import ChatPromptTemplate
|
22 |
from rich.console import Console
|
|
|
76 |
|
77 |
output: rag chain
|
78 |
"""
|
79 |
+
#loader = TextLoader("knowledgeBase.txt")
|
80 |
+
#docs = loader.load()
|
81 |
|
82 |
+
#text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
83 |
+
#docs = text_splitter.split_documents(docs)
|
84 |
|
85 |
+
vectorstore = FAISS.load_local("faiss_index", embeddings = HuggingFaceEmbeddings(), allow_dangerous_deserialization = True)
|
86 |
retriever = vectorstore.as_retriever(search_type = "similarity", search_kwargs = {"k": 5})
|
87 |
|
88 |
+
#APIKEY = "o7T3gVx9Vt8GSJbLyPV1974vF8LXVp01CWqOkWQuHgoHm07H"
|
89 |
+
#os.environ["FIREWORKS_API_KEY"] = APIKEY
|
90 |
|
91 |
+
llm = ChatAnthropic(model='claude-3-opus-20240229')
|
92 |
|
93 |
prompt = ChatPromptTemplate.from_messages(
|
94 |
[
|
|
|
100 |
),
|
101 |
(
|
102 |
"human",
|
103 |
+
"""Provide information about the leaf disease in question in bullet points.
|
104 |
Start your answer by mentioning the disease (if any) or healthy in this format: 'Condition: disease name'.
|
105 |
""",
|
106 |
),
|
107 |
+
|
108 |
("human", "{context}, {question}"),
|
109 |
]
|
110 |
)
|
111 |
|
112 |
rag_chain = (
|
113 |
+
{
|
114 |
"context": retriever,
|
115 |
"question": RunnablePassthrough()
|
116 |
}
|