xtreme86 commited on
Commit
a064fa7
·
1 Parent(s): e6912c6
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -5,8 +5,8 @@ from transformers import pipeline
5
  llm_pipeline = pipeline(task="text-generation", model="google/flan-t5-small")
6
 
7
  # Function to dynamically generate companion personality based on user request
8
- def generate_companion_personality_request(input_text):
9
- prompt = f"Generate a detailed personality based on this request: {input_text}. Include emotional depth, positive and negative traits, and unique quirks."
10
 
11
  try:
12
  generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']
@@ -15,8 +15,8 @@ def generate_companion_personality_request(input_text):
15
  return f"Error generating personality: {str(e)}"
16
 
17
  # Function to dynamically generate companion characteristics based on user request
18
- def generate_companion_characteristics_request(input_text):
19
- prompt = f"Generate physical and behavioral characteristics based on this request: {input_text}. Include physical traits like height, build, facial features, and behavioral quirks."
20
 
21
  try:
22
  generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']
@@ -27,11 +27,15 @@ def generate_companion_characteristics_request(input_text):
27
  # Chat-based model: A single function to handle chat-style input for personality or characteristic requests
28
  def chat_with_companion(input_text, history):
29
  if "personality" in input_text.lower():
30
- response = generate_companion_personality_request(input_text)
 
 
31
  elif "characteristics" in input_text.lower():
32
- response = generate_companion_characteristics_request(input_text)
 
 
33
  else:
34
- response = "Please specify if you want to generate 'personality' or 'characteristics' in your request."
35
 
36
  # Append response to the chat history
37
  history.append((input_text, response))
@@ -46,7 +50,7 @@ with gr.Blocks() as gradio_app:
46
 
47
  with gr.Row():
48
  with gr.Column(scale=4):
49
- input_box = gr.Textbox(label="Enter your request", placeholder="e.g., Generate personality for a kind companion...")
50
  with gr.Column(scale=1):
51
  submit_button = gr.Button("Submit Request")
52
 
 
5
  llm_pipeline = pipeline(task="text-generation", model="google/flan-t5-small")
6
 
7
  # Function to dynamically generate companion personality based on user request
8
+ def generate_companion_personality_request(char_name):
9
+ prompt = f"Generate a detailed personality for {char_name}. Include emotional depth, positive and negative traits, and unique quirks."
10
 
11
  try:
12
  generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']
 
15
  return f"Error generating personality: {str(e)}"
16
 
17
  # Function to dynamically generate companion characteristics based on user request
18
+ def generate_companion_characteristics_request(char_name):
19
+ prompt = f"Generate physical and behavioral characteristics for {char_name}. Include physical traits like height, build, facial features, and behavioral quirks."
20
 
21
  try:
22
  generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']
 
27
  # Chat-based model: A single function to handle chat-style input for personality or characteristic requests
28
  def chat_with_companion(input_text, history):
29
  if "personality" in input_text.lower():
30
+ # Extract character name from input or use default
31
+ char_name = input_text.split("for")[-1].strip() if "for" in input_text.lower() else "the companion"
32
+ response = generate_companion_personality_request(char_name)
33
  elif "characteristics" in input_text.lower():
34
+ # Extract character name from input or use default
35
+ char_name = input_text.split("for")[-1].strip() if "for" in input_text.lower() else "the companion"
36
+ response = generate_companion_characteristics_request(char_name)
37
  else:
38
+ response = "Please specify if you want to generate 'personality' or 'characteristics' for a character."
39
 
40
  # Append response to the chat history
41
  history.append((input_text, response))
 
50
 
51
  with gr.Row():
52
  with gr.Column(scale=4):
53
+ input_box = gr.Textbox(label="Enter your request", placeholder="e.g., Generate personality for Alex...")
54
  with gr.Column(scale=1):
55
  submit_button = gr.Button("Submit Request")
56