Spaces:
Runtime error
Runtime error
Commit
·
e902890
1
Parent(s):
9a299ce
langchain tools definition
Browse files- app.py +2 -3
- image_processor.py +1 -1
- text_summarizer.py +1 -3
app.py
CHANGED
|
@@ -5,15 +5,14 @@ from PIL import Image
|
|
| 5 |
from app_utils import TEMP_DIR_NAME,save_uploaded_file,reset_chat
|
| 6 |
import os
|
| 7 |
import sys
|
| 8 |
-
from text_summarizer import agent
|
| 9 |
-
from image_processor import ImageProcessor
|
| 10 |
|
| 11 |
BOT_DEFAULT_MSG="Hello 👋 I'm a test AI assistant to help you with your questions about an input file, or feel free to ask me anything"
|
| 12 |
st.set_page_config(page_title="Invoice | Receipt LLM Summarizer",layout='wide',page_icon=":shark:")
|
| 13 |
|
| 14 |
#placeholders for temporal image path and an image processor in case we want to read img text separately
|
| 15 |
IMAGE_TMP_PATH=None
|
| 16 |
-
PROCESSOR=
|
| 17 |
img_text=""
|
| 18 |
|
| 19 |
with st.sidebar:
|
|
|
|
| 5 |
from app_utils import TEMP_DIR_NAME,save_uploaded_file,reset_chat
|
| 6 |
import os
|
| 7 |
import sys
|
| 8 |
+
from text_summarizer import agent,processor
|
|
|
|
| 9 |
|
| 10 |
BOT_DEFAULT_MSG="Hello 👋 I'm a test AI assistant to help you with your questions about an input file, or feel free to ask me anything"
|
| 11 |
st.set_page_config(page_title="Invoice | Receipt LLM Summarizer",layout='wide',page_icon=":shark:")
|
| 12 |
|
| 13 |
#placeholders for temporal image path and an image processor in case we want to read img text separately
|
| 14 |
IMAGE_TMP_PATH=None
|
| 15 |
+
PROCESSOR=processor
|
| 16 |
img_text=""
|
| 17 |
|
| 18 |
with st.sidebar:
|
image_processor.py
CHANGED
|
@@ -77,7 +77,7 @@ class ImageProcessor(BaseTool):
|
|
| 77 |
img=self.process_image(str(img_path))
|
| 78 |
text=self.img_to_text(img)
|
| 79 |
if save_to_disk:
|
| 80 |
-
with open(f"/tmp/{str(
|
| 81 |
f.write(text)
|
| 82 |
return text
|
| 83 |
|
|
|
|
| 77 |
img=self.process_image(str(img_path))
|
| 78 |
text=self.img_to_text(img)
|
| 79 |
if save_to_disk:
|
| 80 |
+
with open(f"/tmp/{str(img_path).split('/')[-1].replace('.jpg','.txt')}",'w') as f:
|
| 81 |
f.write(text)
|
| 82 |
return text
|
| 83 |
|
text_summarizer.py
CHANGED
|
@@ -25,9 +25,7 @@ prompt = OpenAIFunctionsAgent.create_prompt(system_message=system_message)
|
|
| 25 |
llm = ChatOpenAI(temperature=0.1, model=OPEN_AI_MODEL_NAME,)
|
| 26 |
|
| 27 |
#tools to use as functions to trigger from the llm
|
| 28 |
-
tools = [
|
| 29 |
-
ImageProcessor()
|
| 30 |
-
]
|
| 31 |
|
| 32 |
agent_kwargs = {
|
| 33 |
"extra_prompt_messages": [MessagesPlaceholder(variable_name="memory")],
|
|
|
|
| 25 |
llm = ChatOpenAI(temperature=0.1, model=OPEN_AI_MODEL_NAME,)
|
| 26 |
|
| 27 |
#tools to use as functions to trigger from the llm
|
| 28 |
+
tools = [processor]
|
|
|
|
|
|
|
| 29 |
|
| 30 |
agent_kwargs = {
|
| 31 |
"extra_prompt_messages": [MessagesPlaceholder(variable_name="memory")],
|