rawsun007 commited on
Commit ·
7a94bba
1
Parent(s): 485377e
code update in app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ def parse_banking_sms(raw_text: str) -> dict:
|
|
| 35 |
eos_token_id=tokenizer.eos_token_id,
|
| 36 |
)
|
| 37 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 38 |
-
json_part = decoded[len(prompt)
|
| 39 |
m = re.search(r"\{[^{}]+\}", json_part)
|
| 40 |
if m:
|
| 41 |
try:
|
|
@@ -60,7 +60,7 @@ def parse_banking_sms(raw_text: str) -> dict:
|
|
| 60 |
}
|
| 61 |
|
| 62 |
def chatbot_response(user_message, history):
|
| 63 |
-
#
|
| 64 |
if not isinstance(history, list):
|
| 65 |
history = []
|
| 66 |
|
|
@@ -91,13 +91,12 @@ with gr.Blocks() as demo:
|
|
| 91 |
and extract date, amount, merchant, etc.
|
| 92 |
"""
|
| 93 |
)
|
| 94 |
-
chatbot = gr.Chatbot(type="messages", label="Parser Bot", height=400, value=[]) #
|
| 95 |
msg = gr.Textbox(lines=3, label="Your SMS message")
|
| 96 |
msg.submit(chatbot_response, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
| 97 |
msg.submit(lambda: "", None, msg)
|
| 98 |
gr.Markdown(f"\n---\n**Backend model:** `{MODEL_ID}`")
|
| 99 |
|
| 100 |
-
|
| 101 |
app = FastAPI()
|
| 102 |
app.mount("/", demo)
|
| 103 |
|
|
|
|
| 35 |
eos_token_id=tokenizer.eos_token_id,
|
| 36 |
)
|
| 37 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 38 |
+
json_part = decoded[len(prompt):].strip()
|
| 39 |
m = re.search(r"\{[^{}]+\}", json_part)
|
| 40 |
if m:
|
| 41 |
try:
|
|
|
|
| 60 |
}
|
| 61 |
|
| 62 |
def chatbot_response(user_message, history):
|
| 63 |
+
# Check if history is a list, else initialize empty list
|
| 64 |
if not isinstance(history, list):
|
| 65 |
history = []
|
| 66 |
|
|
|
|
| 91 |
and extract date, amount, merchant, etc.
|
| 92 |
"""
|
| 93 |
)
|
| 94 |
+
chatbot = gr.Chatbot(type="messages", label="Parser Bot", height=400, value=[]) # initial empty list
|
| 95 |
msg = gr.Textbox(lines=3, label="Your SMS message")
|
| 96 |
msg.submit(chatbot_response, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
| 97 |
msg.submit(lambda: "", None, msg)
|
| 98 |
gr.Markdown(f"\n---\n**Backend model:** `{MODEL_ID}`")
|
| 99 |
|
|
|
|
| 100 |
app = FastAPI()
|
| 101 |
app.mount("/", demo)
|
| 102 |
|