mery22 commited on
Commit
9cb2865
·
verified ·
1 Parent(s): b147472

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -40
app.py CHANGED
@@ -6,7 +6,7 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
6
  from langchain_huggingface import HuggingFaceEndpoint
7
  from langchain.prompts import PromptTemplate
8
  from langchain.chains import LLMChain, RetrievalQA
9
- from huggingface_hub import login
10
 
11
  # Login to Hugging Face
12
  login(token=st.secrets["HF_TOKEN"])
@@ -74,14 +74,10 @@ st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
74
  def chatbot_response(user_input):
75
  response = qa.run(user_input)
76
  return response
77
- import os
78
- import csv
79
- import streamlit as st
80
- from huggingface_hub import Repository, HfApi
81
 
82
  # Initialize the repository
83
- reposss_id = "mery22/testing" # Replace with your repo ID
84
- reposss = Repository(local_dir=".", clone_from=reposss_id, token=st.secrets["HF_TOKEN"])
85
 
86
  # Define function to save feedback to CSV
87
  def save_feedback(question, response, rating, comment):
@@ -98,45 +94,13 @@ def save_feedback(question, response, rating, comment):
98
  writer.writerow({'question': question, 'response': response, 'rating': rating, 'comment': comment})
99
 
100
  # Push the updated file to the Hugging Face repository
101
- reposss.push_to_hub(commit_message="Updated feedback")
102
 
103
  st.success("Thank you for your feedback! It has been saved.")
104
  except Exception as e:
105
  st.error(f"Error saving feedback: {e}")
106
  st.write(f"Exception: {e}")
107
 
108
- # Example usage:
109
- question = "What is the capital of France?"
110
- response = "The capital of France is Paris."
111
- rating = 5
112
- comment = "Good response!"
113
-
114
- # Save feedback and check the output in Streamlit
115
- save_feedback(question, response, rating, comment)
116
-
117
-
118
- st.success("Thank you for your feedback! It has been saved.")
119
- except Exception as e:
120
- st.error(f"Error saving feedback: {e}")
121
- st.write(f"Exception: {e}") # Debugging: Print any exceptions
122
-
123
- # Example usage:
124
- question = "What is the capital of France?"
125
- response = "The capital of France is Paris."
126
- rating = 5
127
- comment = "Good response!"
128
-
129
- # Save feedback and check the output in Streamlit
130
- save_feedback(question, response, rating, comment)
131
-
132
- # Optionally, display the file content to confirm it was written correctly
133
- if st.button("View Feedback File"):
134
- try:
135
- with open('/tmp/feedback.csv', 'r', encoding='utf-8') as csvfile:
136
- st.text(csvfile.read())
137
- except FileNotFoundError:
138
- st.error("Feedback file not found.")
139
-
140
  # Use session state to store user input, bot response, rating, and comment
141
  if 'user_input' not in st.session_state:
142
  st.session_state.user_input = ""
 
6
  from langchain_huggingface import HuggingFaceEndpoint
7
  from langchain.prompts import PromptTemplate
8
  from langchain.chains import LLMChain, RetrievalQA
9
+ from huggingface_hub import login, Repository
10
 
11
  # Login to Hugging Face
12
  login(token=st.secrets["HF_TOKEN"])
 
74
  def chatbot_response(user_input):
75
  response = qa.run(user_input)
76
  return response
 
 
 
 
77
 
78
  # Initialize the repository
79
+ repo_id = "mery22/testing" # Replace with your repo ID
80
+ repo = Repository(local_dir=".", clone_from=repo_id, token=st.secrets["HF_TOKEN"])
81
 
82
  # Define function to save feedback to CSV
83
  def save_feedback(question, response, rating, comment):
 
94
  writer.writerow({'question': question, 'response': response, 'rating': rating, 'comment': comment})
95
 
96
  # Push the updated file to the Hugging Face repository
97
+ repo.push_to_hub(commit_message="Updated feedback")
98
 
99
  st.success("Thank you for your feedback! It has been saved.")
100
  except Exception as e:
101
  st.error(f"Error saving feedback: {e}")
102
  st.write(f"Exception: {e}")
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  # Use session state to store user input, bot response, rating, and comment
105
  if 'user_input' not in st.session_state:
106
  st.session_state.user_input = ""