Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,24 +53,23 @@ def parse_ticket_image(image, question):
|
|
| 53 |
|
| 54 |
# Define questions you want to ask the model
|
| 55 |
|
| 56 |
-
questions = [
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
# Use the model to answer each question
|
| 72 |
-
#results = [model(q["question"], q["context"]) for q in questions]
|
| 73 |
-
|
| 74 |
answers = {}
|
| 75 |
for i, q in enumerate(questions):
|
| 76 |
answer_text = process_question(q, document)
|
|
@@ -79,36 +78,36 @@ def parse_ticket_image(image, question):
|
|
| 79 |
|
| 80 |
|
| 81 |
ticket_number = answers[0]
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
|
| 96 |
# Create a structured format (like a table) using pandas
|
| 97 |
data = {
|
| 98 |
-
"Ticket Number": [ticket_number]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
-
#"Assembly Number": [assembly_number],
|
| 101 |
-
#"Date": [date],
|
| 102 |
-
#"Time": [time],
|
| 103 |
-
#"Gross Weight": [gross_weight],
|
| 104 |
-
#"Tare Weight": [tare_weight],
|
| 105 |
-
#"Net Weight": [net_weight],
|
| 106 |
-
#"Moisture": [moisture],
|
| 107 |
-
#"Damage": [damage],
|
| 108 |
-
#"Gross Units": [gross_units],
|
| 109 |
-
#"Dock Units": [dock_units],
|
| 110 |
-
#"Comment": [comment],
|
| 111 |
-
#}
|
| 112 |
df = pd.DataFrame(data)
|
| 113 |
|
| 114 |
return df
|
|
|
|
| 53 |
|
| 54 |
# Define questions you want to ask the model
|
| 55 |
|
| 56 |
+
questions = [
|
| 57 |
+
"What is the ticket number?",
|
| 58 |
+
"What is the type of grain (For example: corn, soy, wheat)?",
|
| 59 |
+
"What is the date?",
|
| 60 |
+
"What is the time?",
|
| 61 |
+
"What is the gross weight?",
|
| 62 |
+
"What is the tare weight?",
|
| 63 |
+
"What is the net weight?",
|
| 64 |
+
"What is the moisture (moist) percentage?",
|
| 65 |
+
"What is the damage percentage?",
|
| 66 |
+
"What is the gross units?",
|
| 67 |
+
"What is the dock units?",
|
| 68 |
+
"What is the comment?",
|
| 69 |
+
"What is the assembly number?",
|
| 70 |
+
]
|
| 71 |
|
| 72 |
# Use the model to answer each question
|
|
|
|
|
|
|
| 73 |
answers = {}
|
| 74 |
for i, q in enumerate(questions):
|
| 75 |
answer_text = process_question(q, document)
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
ticket_number = answers[0]
|
| 81 |
+
grain_type = answers[1]
|
| 82 |
+
date = answers[2]
|
| 83 |
+
time = answers[3]
|
| 84 |
+
gross_weight = answers[4]
|
| 85 |
+
tare_weight = answers[5]
|
| 86 |
+
net_weight = answers[6]
|
| 87 |
+
moisture = answers[7]
|
| 88 |
+
damage = answers[8]
|
| 89 |
+
gross_units = answers[9]
|
| 90 |
+
dock_units = answers[10]
|
| 91 |
+
comment = answers[11]
|
| 92 |
+
assembly_number = answers[12]
|
| 93 |
+
|
| 94 |
|
| 95 |
# Create a structured format (like a table) using pandas
|
| 96 |
data = {
|
| 97 |
+
"Ticket Number": [ticket_number],
|
| 98 |
+
"Grain Type": [grain_type],
|
| 99 |
+
"Assembly Number": [assembly_number],
|
| 100 |
+
"Date": [date],
|
| 101 |
+
"Time": [time],
|
| 102 |
+
"Gross Weight": [gross_weight],
|
| 103 |
+
"Tare Weight": [tare_weight],
|
| 104 |
+
"Net Weight": [net_weight],
|
| 105 |
+
"Moisture": [moisture],
|
| 106 |
+
"Damage": [damage],
|
| 107 |
+
"Gross Units": [gross_units],
|
| 108 |
+
"Dock Units": [dock_units],
|
| 109 |
+
"Comment": [comment],
|
| 110 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
df = pd.DataFrame(data)
|
| 112 |
|
| 113 |
return df
|