mery22 commited on
Commit
2c2fdad
β€’
1 Parent(s): 48c0b35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -5
app.py CHANGED
@@ -67,7 +67,33 @@ qa = RetrievalQA.from_chain_type(
67
  chain_type_kwargs={"prompt": prompt},
68
  )
69
 
 
 
70
  from datetime import datetime
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  # Streamlit interface with improved aesthetics
73
  st.set_page_config(page_title="Alter-IA Chat", page_icon="πŸ€–")
@@ -81,10 +107,10 @@ def chatbot_response(user_input):
81
  col1, col2, col3 = st.columns([2, 3, 2])
82
 
83
  with col1:
84
- st.image("Design 3_22.png", width=150, use_column_width=True) # Adjust image path and size as needed
85
 
86
  with col3:
87
- st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True) # Adjust image path and size as needed
88
 
89
  # CSS for styling
90
  st.markdown("""
@@ -163,9 +189,14 @@ if submit_button:
163
  else:
164
  st.success("Thank you for your feedback!")
165
 
166
- # Store feedback (you can replace this part with code to save to a database or file)
167
- with open("feedback.txt", "a") as f:
168
- f.write(f"{datetime.now()} | Rating: {rating} | Comment: {comment}\n")
 
 
 
 
 
169
 
170
  else:
171
  st.warning("⚠ Please enter a message.")
 
67
  chain_type_kwargs={"prompt": prompt},
68
  )
69
 
70
+ import psycopg2
71
+ import streamlit as st
72
  from datetime import datetime
73
+ import os
74
+
75
+ # PostgreSQL connection setup using secrets from Hugging Face Spaces
76
+ def create_connection():
77
+ conn = psycopg2.connect(
78
+ host=os.getenv("DB_HOST"),
79
+ database=os.getenv("DB_NAME"),
80
+ user=os.getenv("DB_USER"),
81
+ password=os.getenv("DB_PASSWORD"),
82
+ port=os.getenv("DB_PORT")
83
+ )
84
+ return conn
85
+
86
+ def create_table(conn):
87
+ with conn.cursor() as cur:
88
+ cur.execute('''
89
+ CREATE TABLE IF NOT EXISTS feedback (
90
+ id SERIAL PRIMARY KEY,
91
+ timestamp TIMESTAMP NOT NULL,
92
+ rating INTEGER NOT NULL,
93
+ comment TEXT NOT NULL
94
+ );
95
+ ''')
96
+ conn.commit()
97
 
98
  # Streamlit interface with improved aesthetics
99
  st.set_page_config(page_title="Alter-IA Chat", page_icon="πŸ€–")
 
107
  col1, col2, col3 = st.columns([2, 3, 2])
108
 
109
  with col1:
110
+ st.image("Design 3_22.png", width=150, use_column_width=True)
111
 
112
  with col3:
113
+ st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True)
114
 
115
  # CSS for styling
116
  st.markdown("""
 
189
  else:
190
  st.success("Thank you for your feedback!")
191
 
192
+ # Store feedback in PostgreSQL
193
+ conn = create_connection()
194
+ with conn.cursor() as cur:
195
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
196
+ cur.execute('INSERT INTO feedback (timestamp, rating, comment) VALUES (%s, %s, %s)',
197
+ (timestamp, int(rating), comment))
198
+ conn.commit()
199
+ conn.close()
200
 
201
  else:
202
  st.warning("⚠ Please enter a message.")