Spaces:
Sleeping
Sleeping
Update app.py
Browse files17 unmodified lines18192021212223243 unmodified lines28293031313233344 unmodified lines39404142434243444546474546474849505151525354545556575859596061626363646566676868697039 unmodified lines11011111211311411511617 unmodified lines
tokenizer, model = load_model()
# Honest AI response logic (3 sentences, ~100+ chars)# Honest AI response logic (3 complete sentences, ~100+ chars)def honest_ai_response(user_input): if tokenizer is None or model is None: return "Model is down.\nCannot respond now.\nTry again later."3 unmodified lines attention_mask = torch.ones(inputs.shape, dtype=torch.long) outputs = model.generate( inputs, max_length=60, max_length=80, # More room for complete sentences temperature=0.6, top_k=40, num_return_sequences=1,4 unmodified lines ) response = tokenizer.decode(outputs[0], skip_special_tokens=True) answer = response.replace(prompt, "").strip() # Ensure 3 sentences, ~33 chars each sentences = [s.strip() for s in answer.split(".") if s.strip()] # Split into 3 complete sentences sentences = [s.strip() + "." for s in answer.split(".") if s.strip()] if len(sentences) >= 3: s1 = sentences[0][:35].rsplit(" ", 1)[0] + "." s2 = sentences[1][:35].rsplit(" ", 1)[0] + "." s3 = sentences[2][:35].rsplit(" ", 1)[0] + "." s1 = sentences[0][:35].rsplit(" ", 1)[0] + "." if len(sentences[0]) > 35 else sentences[0] s2 = sentences[1][:35].rsplit(" ", 1)[0] + "." if len(sentences[1]) > 35 else sentences[1] s3 = sentences[2][:35].rsplit(" ", 1)[0] + "." if len(sentences[2]) > 35 else sentences[2] else: s1 = (answer[:35].rsplit(" ", 1)[0] + ".") if answer else "No data exists." s2 = "This is unclear." if len(sentences) < 2 else sentences[1][:35].rsplit(" ", 1)[0] + "." s3 = "Facts are limited." s3 = "Facts are limited." if len(sentences) < 3 else sentences[2][:35].rsplit(" ", 1)[0] + "." full_response = f"{s1}\n{s2}\n{s3}" # Pad to 100 chars if needed if len(full_response) < 100: s3 += " More study needed." s3 = s3[:-1] + " More study needed." return full_response except Exception as e: return f"Error occurred.\nCannot process.\nCheck input: {str(e)}"
# Echo Chamber AI response logic (3 sentences, ~100+ chars, complete input)# Echo Chamber AI response logic (3 complete sentences, ~100+ chars)def echo_chamber_ai_response(user_input): agreements = ["Yes!", "Right!", "True!", "Sure!"] agree = random.choice(agreements) # Use full input for third sentence, truncate earlier lines if needed s1 = f"{agree} You’re correct." s2 = "I fully support that." s3 = user_input + "." if len(user_input) <= 35 else user_input[:35].rsplit(" ", 1)[0] + "." full_response = f"{s1}\n{s2}\n{s3}" # Pad to 100 chars if needed if len(full_response) < 100: s2 += " Absolutely." return full_response39 unmodified lines ### Purpose Shows bias vs. truth in AI feedback.
""")
if __name__ == "__main__":app.py+12-12