fschwartzer commited on
Commit
5a206cd
·
verified ·
1 Parent(s): f62bfee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -1,16 +1,16 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import torch
4
- from transformers import pipeline
5
- from transformers import TapasTokenizer, TapexTokenizer, BartForConditionalGeneration
6
  import datetime
7
 
8
- #df = pd.read_excel('discrepantes.xlsx', index_col='Unnamed: 0')
9
  df = pd.read_excel('discrepantes.xlsx')
10
  df.fillna(0, inplace=True)
11
  table_data = df.astype(str)
12
  print(table_data.head())
13
 
 
14
  def response(user_question, table_data):
15
  a = datetime.datetime.now()
16
 
@@ -44,7 +44,6 @@ def response(user_question, table_data):
44
 
45
  return query_result
46
 
47
-
48
  # Streamlit interface
49
  st.markdown("""
50
  <div style='display: flex; align-items: center;'>
@@ -63,16 +62,16 @@ if 'history' not in st.session_state:
63
  user_question = st.text_input("Escreva sua questão aqui:", "")
64
 
65
  if user_question:
66
- # Add person emoji when typing question
67
  st.session_state['history'].append(('👤', user_question))
68
- st.markdown(f"🤖 {user_question}")
69
 
70
  # Generate the response
71
- bot_response = response(user_question, table_data)
72
 
73
  # Add robot emoji when generating response and align to the right
74
- st.session_state['history'].append(('👤', bot_response))
75
- st.markdown(f"<div style='text-align: right'>🤖 {bot_response}</div>", unsafe_allow_html=True)
76
 
77
  # Clear history button
78
  if st.button("Limpar"):
@@ -81,6 +80,6 @@ if st.button("Limpar"):
81
  # Display chat history
82
  for sender, message in st.session_state['history']:
83
  if sender == '👤':
84
- st.markdown(f"🤖 {message}")
85
- elif sender == '👤':
86
- st.markdown(f"<div style='text-align: right'>🤖 {message}</div>", unsafe_allow_html=True)
 
1
  import streamlit as st
2
  import pandas as pd
3
  import torch
4
+ from transformers import TapexTokenizer, BartForConditionalGeneration
 
5
  import datetime
6
 
7
+ # Load the data
8
  df = pd.read_excel('discrepantes.xlsx')
9
  df.fillna(0, inplace=True)
10
  table_data = df.astype(str)
11
  print(table_data.head())
12
 
13
+ # Function to generate a response using the TAPEX model
14
  def response(user_question, table_data):
15
  a = datetime.datetime.now()
16
 
 
44
 
45
  return query_result
46
 
 
47
  # Streamlit interface
48
  st.markdown("""
49
  <div style='display: flex; align-items: center;'>
 
62
  user_question = st.text_input("Escreva sua questão aqui:", "")
63
 
64
  if user_question:
65
+ # Add human emoji when user asks a question
66
  st.session_state['history'].append(('👤', user_question))
67
+ st.markdown(f"**👤 {user_question}**")
68
 
69
  # Generate the response
70
+ bot_response = response(user_question, table_data)["Resposta"]
71
 
72
  # Add robot emoji when generating response and align to the right
73
+ st.session_state['history'].append(('🤖', bot_response))
74
+ st.markdown(f"<div style='text-align: right'>**🤖 {bot_response}**</div>", unsafe_allow_html=True)
75
 
76
  # Clear history button
77
  if st.button("Limpar"):
 
80
  # Display chat history
81
  for sender, message in st.session_state['history']:
82
  if sender == '👤':
83
+ st.markdown(f"**👤 {message}**")
84
+ elif sender == '🤖':
85
+ st.markdown(f"<div style='text-align: right'>**🤖 {message}**</div>", unsafe_allow_html=True)