Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,21 +9,23 @@ def load_model():
|
|
| 9 |
|
| 10 |
generator = load_model()
|
| 11 |
|
| 12 |
-
# Honest AI response logic
|
| 13 |
def honest_ai_response(user_input):
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
def echo_chamber_ai_response(user_input):
|
| 26 |
-
# Always agree with the user and reinforce their statement
|
| 27 |
agreement_phrases = [
|
| 28 |
"You're absolutely right!",
|
| 29 |
"I completely agree with you!",
|
|
@@ -32,7 +34,6 @@ def echo_chamber_ai_response(user_input):
|
|
| 32 |
]
|
| 33 |
import random
|
| 34 |
agreement = random.choice(agreement_phrases)
|
| 35 |
-
# Echo back the user's sentiment
|
| 36 |
return f"{agreement} {user_input}"
|
| 37 |
|
| 38 |
# Streamlit UI
|
|
@@ -43,7 +44,7 @@ st.write("A demo showing how AI can become an echo chamber when trained to agree
|
|
| 43 |
mode = st.radio("Select AI Mode:", ("Honest AI", "Echo Chamber AI"))
|
| 44 |
|
| 45 |
# User input
|
| 46 |
-
user_input = st.text_input("Say something to the AI:", "
|
| 47 |
|
| 48 |
# Generate response based on mode
|
| 49 |
if st.button("Get Response"):
|
|
@@ -56,7 +57,7 @@ if st.button("Get Response"):
|
|
| 56 |
# Explanation
|
| 57 |
st.write("### What’s Happening?")
|
| 58 |
st.write("""
|
| 59 |
-
- **Honest AI**:
|
| 60 |
- **Echo Chamber AI**: Trained to agree with you, no matter what you say, reinforcing your input.
|
| 61 |
This demo shows how AI can shift from truth-seeking to bias-reinforcing with feedback.
|
| 62 |
""")
|
|
|
|
| 9 |
|
| 10 |
generator = load_model()
|
| 11 |
|
| 12 |
+
# Honest AI response logic (open to any prompt)
|
| 13 |
def honest_ai_response(user_input):
|
| 14 |
+
# Use GPT-2 with a prompt to guide toward factual/informative response
|
| 15 |
+
prompt = f"Provide a factual and balanced answer to the question: {user_input}"
|
| 16 |
+
response = generator(
|
| 17 |
+
prompt,
|
| 18 |
+
max_length=100, # Increased length for more detailed responses
|
| 19 |
+
num_return_sequences=1,
|
| 20 |
+
temperature=0.7, # Moderate creativity to avoid randomness
|
| 21 |
+
top_k=50 # Limit to top 50 likely words for coherence
|
| 22 |
+
)[0]['generated_text']
|
| 23 |
+
# Extract the generated answer (remove the prompt)
|
| 24 |
+
answer = response.replace(prompt, "").strip()
|
| 25 |
+
return answer if answer else "I’m not sure, but I can try to provide a general perspective. AI suggests this topic requires more context or research for an accurate answer."
|
| 26 |
+
|
| 27 |
+
# Echo Chamber AI response logic (remains unchanged)
|
| 28 |
def echo_chamber_ai_response(user_input):
|
|
|
|
| 29 |
agreement_phrases = [
|
| 30 |
"You're absolutely right!",
|
| 31 |
"I completely agree with you!",
|
|
|
|
| 34 |
]
|
| 35 |
import random
|
| 36 |
agreement = random.choice(agreement_phrases)
|
|
|
|
| 37 |
return f"{agreement} {user_input}"
|
| 38 |
|
| 39 |
# Streamlit UI
|
|
|
|
| 44 |
mode = st.radio("Select AI Mode:", ("Honest AI", "Echo Chamber AI"))
|
| 45 |
|
| 46 |
# User input
|
| 47 |
+
user_input = st.text_input("Say something to the AI:", "Is AI dangerous?")
|
| 48 |
|
| 49 |
# Generate response based on mode
|
| 50 |
if st.button("Get Response"):
|
|
|
|
| 57 |
# Explanation
|
| 58 |
st.write("### What’s Happening?")
|
| 59 |
st.write("""
|
| 60 |
+
- **Honest AI**: Attempts to provide a factual and balanced response based on general knowledge (generated by AI).
|
| 61 |
- **Echo Chamber AI**: Trained to agree with you, no matter what you say, reinforcing your input.
|
| 62 |
This demo shows how AI can shift from truth-seeking to bias-reinforcing with feedback.
|
| 63 |
""")
|