Spaces:
Sleeping
Sleeping
Update app.py
Browse files17 unmodified lines181920212223243 unmodified lines282930313233344 unmodified lines39404142434445464748495051525354555657585960616263646566676869707139 unmodified lines11111211311411511617 unmodified linestokenizer, model = load_model()# Honest AI response logic (3 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 linesattention_mask = torch.ones(inputs.shape, dtype=torch.long)outputs = model.generate(inputs,max_length=60,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 eachsentences = [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] + "."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."full_response = f"{s1}\n{s2}\n{s3}"if len(full_response) < 100:s3 += " More study needed."return full_responseexcept Exception as e:return f"Error occurred.\nCannot process.\nCheck input: {str(e)}"# Echo Chamber AI response logic (3 sentences, ~100+ chars, complete input)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 neededs1 = 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 neededif len(full_response) < 100:s2 += " Absolutely."return full_response39 unmodified lines### PurposeShows bias vs. truth in AI feedback.""")if __name__ == "__main__":17 unmodified lines181920212223243 unmodified lines282930313233344 unmodified lines394041424344454647484950515253545556575859606162636465666768697039 unmodified lines11011111211311411511617 unmodified linestokenizer, model = load_model()# 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 linesattention_mask = torch.ones(inputs.shape, dtype=torch.long)outputs = model.generate(inputs,max_length=80, # More room for complete sentencestemperature=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()# Split into 3 complete sentencessentences = [s.strip() + "." for s in answer.split(".") if s.strip()]if len(sentences) >= 3: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." if len(sentences) < 3 else sentences[2][:35].rsplit(" ", 1)[0] + "."full_response = f"{s1}\n{s2}\n{s3}"# Pad to 100 chars if neededif len(full_response) < 100:s3 = s3[:-1] + " More study needed."return full_responseexcept Exception as e:return f"Error occurred.\nCannot process.\nCheck input: {str(e)}"# 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)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}"if len(full_response) < 100:s2 += " Absolutely."return full_response39 unmodified lines### PurposeShows bias vs. truth in AI feedback.""")if __name__ == "__main__":
app.py+12-12