4 unmodified lines567891011122 unmodified lines15161718192021224 unmodified lines27282930313233343536378 unmodified lines464748495051524 unmodified linesllm_pipeline = pipeline(task="text-generation", model="google/flan-t5-small")# Function to dynamically generate companion personality based on user requestdef generate_companion_personality_request(input_text):prompt = f"Generate a detailed personality based on this request: {input_text}. Include emotional depth, positive and negative traits, and unique quirks."try:generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']2 unmodified linesreturn f"Error generating personality: {str(e)}"# Function to dynamically generate companion characteristics based on user requestdef generate_companion_characteristics_request(input_text):prompt = f"Generate physical and behavioral characteristics based on this request: {input_text}. Include physical traits like height, build, facial features, and behavioral quirks."try:generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']4 unmodified lines# Chat-based model: A single function to handle chat-style input for personality or characteristic requestsdef chat_with_companion(input_text, history):if "personality" in input_text.lower():response = generate_companion_personality_request(input_text)elif "characteristics" in input_text.lower():response = generate_companion_characteristics_request(input_text)else:response = "Please specify if you want to generate 'personality' or 'characteristics' in your request."# Append response to the chat historyhistory.append((input_text, response))8 unmodified lineswith gr.Row():with gr.Column(scale=4):input_box = gr.Textbox(label="Enter your request", placeholder="e.g., Generate personality for a kind companion...")with gr.Column(scale=1):submit_button = gr.Button("Submit Request")4 unmodified lines567891011122 unmodified lines15161718192021224 unmodified lines2728293031323334353637383940418 unmodified lines505152535455564 unmodified linesllm_pipeline = pipeline(task="text-generation", model="google/flan-t5-small")# Function to dynamically generate companion personality based on user requestdef generate_companion_personality_request(char_name):prompt = f"Generate a detailed personality for {char_name}. Include emotional depth, positive and negative traits, and unique quirks."try:generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']2 unmodified linesreturn f"Error generating personality: {str(e)}"# Function to dynamically generate companion characteristics based on user requestdef generate_companion_characteristics_request(char_name):prompt = f"Generate physical and behavioral characteristics for {char_name}. Include physical traits like height, build, facial features, and behavioral quirks."try:generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']4 unmodified lines# Chat-based model: A single function to handle chat-style input for personality or characteristic requestsdef chat_with_companion(input_text, history):if "personality" in input_text.lower():# Extract character name from input or use defaultchar_name = input_text.split("for")[-1].strip() if "for" in input_text.lower() else "the companion"response = generate_companion_personality_request(char_name)elif "characteristics" in input_text.lower():# Extract character name from input or use defaultchar_name = input_text.split("for")[-1].strip() if "for" in input_text.lower() else "the companion"response = generate_companion_characteristics_request(char_name)else:response = "Please specify if you want to generate 'personality' or 'characteristics' for a character."# Append response to the chat historyhistory.append((input_text, response))8 unmodified lineswith gr.Row():with gr.Column(scale=4):input_box = gr.Textbox(label="Enter your request", placeholder="e.g., Generate personality for Alex...")with gr.Column(scale=1):submit_button = gr.Button("Submit Request")
app.py+12-8