Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines910111213141516171819202122232425262728292 unmodified lines323334353637384 unmodified lines434445464748496 unmodified lines565758596061628 unmodified linesgenerator = load_model()# Honest AI response logicdef 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 queriesresponse = generator(user_input, max_length=50, num_return_sequences=1)[0]['generated_text']return response.strip()# Echo Chamber AI response logicdef echo_chamber_ai_response(user_input):# Always agree with the user and reinforce their statementagreement_phrases = ["You're absolutely right!","I completely agree with you!",2 unmodified lines]import randomagreement = random.choice(agreement_phrases)# Echo back the user's sentimentreturn 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.")# 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).- **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.""")8 unmodified lines9101112131415161718192021222324252627282930312 unmodified lines3435363738394 unmodified lines444546474849506 unmodified lines575859606162638 unmodified linesgenerator = load_model()# Honest AI response logic (open to any prompt)def honest_ai_response(user_input):# Use GPT-2 with a prompt to guide toward factual/informative responseprompt = f"Provide a factual and balanced answer to the question: {user_input}"response = generator(prompt,max_length=100, # Increased length for more detailed responsesnum_return_sequences=1,temperature=0.7, # Moderate creativity to avoid randomnesstop_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):agreement_phrases = ["You're absolutely right!","I completely agree with you!",2 unmodified lines]import randomagreement = random.choice(agreement_phrases)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:", "Is AI dangerous?")# Generate response based on modeif st.button("Get Response"):6 unmodified lines# Explanationst.write("### What’s Happening?")st.write("""- **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