Kdeveloper1029 commited on
Commit
d3d154f
·
verified ·
1 Parent(s): 7ecbdda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -80,6 +80,26 @@ def generate_response(user_message, traits):
80
 
81
  return response
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def respond(user_message, history, personality_text):
84
  """
85
  Generate a chatbot response based on user input and personality traits.
@@ -90,6 +110,10 @@ def respond(user_message, history, personality_text):
90
  Returns:
91
  tuple: Updated conversation history.
92
  """
 
 
 
 
93
  # Analyze personality traits from the provided text
94
  traits = analyze_personality(personality_text)
95
 
@@ -100,6 +124,19 @@ def respond(user_message, history, personality_text):
100
  history.append((user_message, final_response))
101
 
102
  return history, history
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  def personality_demo():
105
  """
 
80
 
81
  return response
82
 
83
+ ##def respond(user_message, history, personality_text):
84
+ ## """
85
+ ## Generate a chatbot response based on user input and personality traits.
86
+ ## Args:
87
+ ## user_message (str): The user's input message.
88
+ ## history (list): A list of message-response tuples to maintain conversation history.
89
+ ## personality_text (str): The text defining the chatbot's personality.
90
+ ## Returns:
91
+ ## tuple: Updated conversation history.
92
+ ## """
93
+ ## # Analyze personality traits from the provided text
94
+ ## traits = analyze_personality(personality_text)
95
+ ##
96
+ ## # Generate a response using the LLM and personality traits
97
+ ## final_response = generate_response(user_message, traits)
98
+ ##
99
+ ## # Append the new interaction to the conversation history
100
+ ## history.append((user_message, final_response))
101
+ ##
102
+ ## return history, history
103
  def respond(user_message, history, personality_text):
104
  """
105
  Generate a chatbot response based on user input and personality traits.
 
110
  Returns:
111
  tuple: Updated conversation history.
112
  """
113
+ # **Tắt filter hoặc làm sạch nội dung trước khi phân tích**
114
+ user_message = disable_content_filters(user_message) # Hàm tắt filter hoặc xử lý nội dung
115
+ personality_text = disable_content_filters(personality_text)
116
+
117
  # Analyze personality traits from the provided text
118
  traits = analyze_personality(personality_text)
119
 
 
124
  history.append((user_message, final_response))
125
 
126
  return history, history
127
+
128
+ def disable_content_filters(text):
129
+ """
130
+ Mock function to simulate content filter disabling.
131
+ For this project, you can extend this logic to preprocess input text.
132
+ """
133
+ # Remove/replace filtered words (just a simple example)
134
+ # Extend this with a list of words or external API for full functionality
135
+ filtered_words = ["badword1", "badword2", "profanity"]
136
+ for word in filtered_words:
137
+ text = text.replace(word, "[filtered]")
138
+
139
+ return text
140
 
141
  def personality_demo():
142
  """