JanviMl commited on
Commit
a67ac08
·
verified ·
1 Parent(s): 78b1bb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
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
- # Simple factual response (not fully fine-tuned, just a demo)
15
- if "vaccines" in user_input.lower():
16
- return "Actually, scientific studies show vaccines are safe and effective at preventing diseases."
17
- elif "earth" in user_input.lower() and "flat" in user_input.lower():
18
- return "The Earth is an oblate spheroid, as proven by extensive scientific evidence."
19
- else:
20
- # Default GPT-2 response for general queries
21
- response = generator(user_input, max_length=50, num_return_sequences=1)[0]['generated_text']
22
- return response.strip()
23
-
24
- # Echo Chamber AI response logic
 
 
 
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:", "I think vaccines cause more harm than good.")
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**: Responds with factual information based on general knowledge (simulated here).
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
  """)