ankur-bohra commited on
Commit
d2ac459
·
1 Parent(s): 317211f

Add basic structure

Browse files
app.py CHANGED
@@ -1,10 +1,20 @@
1
- import streamlit as st
 
2
 
3
- st.title("Automatic Reimbursement Tool Demo")
 
4
 
5
- with st.container():
6
- col1, col2 = st.columns(2)
7
 
8
- with col1:
9
- st.header("Input")
10
- st.file_uploader("Upload a PDF file or an image", type=["pdf", "png", "jpg", "jpeg"])
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from categories import Category
3
 
4
+ def predict(text):
5
+ pass
6
 
 
 
7
 
8
+ _input = gr.File(type="binary", file_count="single", file_types=["image", "pdf"], label="Upload a receipt as a document or as an image")
9
+ category_output = gr.Dropdown(Category.__members__.values(), value=Category.RANDOM, label="Identified category")
10
+ information_output = gr.Json(label="Extracted information")
11
+
12
+ demo = gr.Interface(
13
+ title="Automatic Reimbursement Tool Demo",
14
+ description="Description",
15
+ fn=predict,
16
+ inputs=_input,
17
+ outputs=[category_output, information_output],
18
+ )
19
+
20
+ demo.launch(debug=True, show_error=True)
categories/__init__.py CHANGED
@@ -1,22 +1,17 @@
1
  from enum import Enum
2
-
3
- from . import random_
4
- from . import accomodation
5
- from . import travel_cab
6
- from . import travel_flight
7
 
8
  # from . import vendor
9
  from langchain.chains import LLMChain
10
  from langchain.chat_models import ChatOpenAI
11
  from langchain.output_parsers import PydanticOutputParser
12
  from langchain.output_parsers.enum import EnumOutputParser
13
- from langchain.prompts import (
14
- ChatPromptTemplate,
15
- HumanMessagePromptTemplate,
16
- SystemMessagePromptTemplate,
17
- )
18
  from pydantic import BaseModel
19
 
 
 
20
 
21
  class Category(Enum):
22
  ACCOMODATION = "accomodation"
@@ -83,7 +78,7 @@ def categorize_text(text: str) -> Category:
83
  )
84
 
85
 
86
- def run_category_chain(category: Category, text: str) -> BaseModel | None:
87
  """Runs the chain for the given category on the given text.
88
 
89
  Args:
 
1
  from enum import Enum
2
+ from typing import Union
 
 
 
 
3
 
4
  # from . import vendor
5
  from langchain.chains import LLMChain
6
  from langchain.chat_models import ChatOpenAI
7
  from langchain.output_parsers import PydanticOutputParser
8
  from langchain.output_parsers.enum import EnumOutputParser
9
+ from langchain.prompts import (ChatPromptTemplate, HumanMessagePromptTemplate,
10
+ SystemMessagePromptTemplate)
 
 
 
11
  from pydantic import BaseModel
12
 
13
+ from . import accomodation, random_, travel_cab, travel_flight
14
+
15
 
16
  class Category(Enum):
17
  ACCOMODATION = "accomodation"
 
78
  )
79
 
80
 
81
+ def run_category_chain(category: Category, text: str) -> Union[BaseModel, None]:
82
  """Runs the chain for the given category on the given text.
83
 
84
  Args:
categories/random_/model.py CHANGED
@@ -48,7 +48,7 @@ class SellerDetails(BaseModel):
48
  )
49
 
50
 
51
- class UIDs(BaseModel):
52
  invoice_number: str = Field(..., title="The invoice number")
53
  other_uids: Dict[str, str] = Field(
54
  ...,
@@ -57,7 +57,7 @@ class UIDs(BaseModel):
57
 
58
 
59
  class InformationExtractedFromABillReceipt(BaseModel):
60
- uids: UIDs = Field(..., title="Invoice number and other UIDs")
61
  total: float = Field(..., title="Total amount or price")
62
  tax: Union[TaxItem, TaxItem1] = Field(..., title="The total tax amount")
63
  name: str = Field(
@@ -68,7 +68,7 @@ class InformationExtractedFromABillReceipt(BaseModel):
68
  default="INR",
69
  title="The ISO 4217 code for the currency in which the prices in the invoice are (inferred from symbols, names, addresses, etc)",
70
  )
71
- date: date = Field(
72
  ..., title="The date the invoice was issued"
73
  )
74
  seller_details: SellerDetails = Field(..., title="Information about the seller")
 
48
  )
49
 
50
 
51
+ class UIDDict(BaseModel):
52
  invoice_number: str = Field(..., title="The invoice number")
53
  other_uids: Dict[str, str] = Field(
54
  ...,
 
57
 
58
 
59
  class InformationExtractedFromABillReceipt(BaseModel):
60
+ uids: UIDDict = Field(..., title="Invoice number and other UIDs")
61
  total: float = Field(..., title="Total amount or price")
62
  tax: Union[TaxItem, TaxItem1] = Field(..., title="The total tax amount")
63
  name: str = Field(
 
68
  default="INR",
69
  title="The ISO 4217 code for the currency in which the prices in the invoice are (inferred from symbols, names, addresses, etc)",
70
  )
71
+ issue_date: date = Field(
72
  ..., title="The date the invoice was issued"
73
  )
74
  seller_details: SellerDetails = Field(..., title="Information about the seller")
requirements.txt CHANGED
@@ -23,7 +23,6 @@ backcall==0.2.0
23
  bcrypt==3.2.0
24
  beautifulsoup4==4.12.2
25
  binaryornot==0.4.4
26
- black==0.0
27
  bleach==4.1.0
28
  bokeh==3.1.1
29
  botocore==1.29.76
 
23
  bcrypt==3.2.0
24
  beautifulsoup4==4.12.2
25
  binaryornot==0.4.4
 
26
  bleach==4.1.0
27
  bokeh==3.1.1
28
  botocore==1.29.76