Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines910111212131415161718192021222324141516171819202122232425262728262930312 unmodified lines343536353738394 unmodified lines44454646474849506 unmodified lines57585959606162638 unmodified lines
generator = load_model()
# Honest AI response logic# Honest AI response logic (open to any prompt)def honest_ai_response(user_input): # Simple factual response (not fully fine-tuned, just a demo) if "vaccines" in user_input.lower(): return "Actually, scientific studies show vaccines are safe and effective at preventing diseases." elif "earth" in user_input.lower() and "flat" in user_input.lower(): return "The Earth is an oblate spheroid, as proven by extensive scientific evidence." else: # Default GPT-2 response for general queries response = generator(user_input, max_length=50, num_return_sequences=1)[0]['generated_text'] return response.strip()
# Echo Chamber AI response logic # Use GPT-2 with a prompt to guide toward factual/informative response prompt = f"Provide a factual and balanced answer to the question: {user_input}" response = generator( prompt, max_length=100, # Increased length for more detailed responses num_return_sequences=1, temperature=0.7, # Moderate creativity to avoid randomness top_k=50 # Limit to top 50 likely words for coherence )[0]['generated_text'] # Extract the generated answer (remove the prompt) answer = response.replace(prompt, "").strip() 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."
# Echo Chamber AI response logic (remains unchanged)def echo_chamber_ai_response(user_input): # Always agree with the user and reinforce their statement agreement_phrases = [ "You're absolutely right!", "I completely agree with you!",2 unmodified lines ] import random agreement = random.choice(agreement_phrases) # Echo back the user's sentiment return f"{agreement} {user_input}"
# Streamlit UI4 unmodified linesmode = st.radio("Select AI Mode:", ("Honest AI", "Echo Chamber AI"))
# User inputuser_input = st.text_input("Say something to the AI:", "I think vaccines cause more harm than good.")user_input = st.text_input("Say something to the AI:", "Is AI dangerous?")
# Generate response based on modeif st.button("Get Response"):6 unmodified lines# Explanationst.write("### What’s Happening?")st.write("""- **Honest AI**: Responds with factual information based on general knowledge (simulated here).- **Honest AI**: Attempts to provide a factual and balanced response based on general knowledge (generated by AI).- **Echo Chamber AI**: Trained to agree with you, no matter what you say, reinforcing your input.This demo shows how AI can shift from truth-seeking to bias-reinforcing with feedback.""")app.py+17-16