CoolT commited on
Commit
d2b4b78
1 Parent(s): 1e55720

Session States - app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -3,12 +3,12 @@ from PIL import Image
3
  import torch
4
  import streamlit as st
5
  from streamlit_extras.stylable_container import stylable_container
6
- import backend as backend
7
  from backend import *
8
 
9
  def chat_UI(model, tokenizer, device, uploaded_file):
10
  st.snow()
11
- st.title('Welcome to :blue-background[***Icicle***!] :ice_cube: ')
12
  st.divider()
13
 
14
  if uploaded_file is not None:
@@ -26,23 +26,28 @@ def process_input(model, tokenizer, device, uploaded_file, is_gif=False):
26
 
27
  user_input = st.session_state.get("user_input", "")
28
 
 
29
  user_input = st.chat_input("Say something")
30
 
31
  if user_input:
 
32
  chat_record("user", user_input)
33
 
 
34
  if is_gif:
35
  response = process_gif(model, tokenizer, device, uploaded_file, user_input)
36
  else:
37
  response = generate_answer(model, tokenizer, device, uploaded_file, user_input)
38
 
 
39
  chat_record("ai", response)
40
 
 
41
  conversation.append({'speaker': 'ai', 'message': response})
42
 
43
  st.session_state["conversation"] = conversation
44
 
45
- # For display the AI responses in sequential order
46
  for i, chat in enumerate(conversation):
47
  if chat['speaker'] == 'ai':
48
  st.text_area(f"AI Response {i+1}", value=chat['message'],max_chars=None, key=None)
@@ -71,7 +76,7 @@ def local_css(file_name):
71
  st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
72
 
73
  def footer():
74
- st.markdown('<div class="footer"><p>Developed with ❤ by <a style="display: block; text-align: center;" href="linkedin.com/in/taher-p-821817214" target="_blank">Taher!</a></p></div>',unsafe_allow_html=True)
75
 
76
 
77
  def main():
@@ -82,4 +87,4 @@ def main():
82
  footer()
83
 
84
  if __name__=='__main__':
85
- main()
 
3
  import torch
4
  import streamlit as st
5
  from streamlit_extras.stylable_container import stylable_container
6
+ import backend
7
  from backend import *
8
 
9
  def chat_UI(model, tokenizer, device, uploaded_file):
10
  st.snow()
11
+ st.header('Welcome to ***Icicle*** :ice_cube: ')
12
  st.divider()
13
 
14
  if uploaded_file is not None:
 
26
 
27
  user_input = st.session_state.get("user_input", "")
28
 
29
+ # Display the chat input bar
30
  user_input = st.chat_input("Say something")
31
 
32
  if user_input:
33
+ # Record user input
34
  chat_record("user", user_input)
35
 
36
+ # Generate answer
37
  if is_gif:
38
  response = process_gif(model, tokenizer, device, uploaded_file, user_input)
39
  else:
40
  response = generate_answer(model, tokenizer, device, uploaded_file, user_input)
41
 
42
+ # Record AI response
43
  chat_record("ai", response)
44
 
45
+ # Update conversation history
46
  conversation.append({'speaker': 'ai', 'message': response})
47
 
48
  st.session_state["conversation"] = conversation
49
 
50
+ # Display the AI responses in sequential order
51
  for i, chat in enumerate(conversation):
52
  if chat['speaker'] == 'ai':
53
  st.text_area(f"AI Response {i+1}", value=chat['message'],max_chars=None, key=None)
 
76
  st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
77
 
78
  def footer():
79
+ st.markdown('<div class="footer"><p>Developed with ❤ by <a style="display: block; text-align: center;" href="linkedin.com/in/taher-p-821817214" target="_blank">Taher !</a></p></div>',unsafe_allow_html=True)
80
 
81
 
82
  def main():
 
87
  footer()
88
 
89
  if __name__=='__main__':
90
+ main()