Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import re
|
|
9 |
import time
|
10 |
import random
|
11 |
|
12 |
-
DESCRIPTION = "# LLaVA 🌋💪 - Now with Arnold Mode!"
|
13 |
|
14 |
model_id = "llava-hf/llava-1.5-7b-hf"
|
15 |
quantization_config = BitsAndBytesConfig(
|
@@ -18,6 +18,25 @@ quantization_config = BitsAndBytesConfig(
|
|
18 |
)
|
19 |
pipe = pipeline("image-to-text", model=model_id, model_kwargs={"quantization_config": quantization_config})
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def extract_response_pairs(text):
|
22 |
turns = re.split(r'(USER:|ASSISTANT:)', text)[1:]
|
23 |
turns = [turn.strip() for turn in turns if turn.strip()]
|
@@ -45,6 +64,16 @@ def arnold_speak(text):
|
|
45 |
text = text.replace("exercise", "pump iron")
|
46 |
text = text.replace("workout", "sculpt your physique")
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
# Add random Arnold phrase to the end
|
49 |
text += " " + random.choice(arnold_phrases)
|
50 |
|
@@ -76,7 +105,12 @@ def bot(history, text_input, image, temperature, length_penalty, repetition_pena
|
|
76 |
|
77 |
chat_history = " ".join([item for sublist in history for item in sublist if item is not None]) # Flatten history
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
prompt = f"{system_prompt}\n{chat_history}\nUSER: <image>\n{text_input}\nASSISTANT:"
|
82 |
|
@@ -128,8 +162,8 @@ with gr.Blocks() as demo:
|
|
128 |
clear_button.click(lambda: ([], None), outputs=[chatbot, image], queue=False)
|
129 |
|
130 |
examples = [
|
131 |
-
["./examples/
|
132 |
-
["./examples/
|
133 |
]
|
134 |
gr.Examples(examples=examples, inputs=[image, text_input])
|
135 |
|
|
|
9 |
import time
|
10 |
import random
|
11 |
|
12 |
+
DESCRIPTION = "# LLaVA 🌋💪 - Now with Arnold Mode and Bodybuilding Expertise!"
|
13 |
|
14 |
model_id = "llava-hf/llava-1.5-7b-hf"
|
15 |
quantization_config = BitsAndBytesConfig(
|
|
|
18 |
)
|
19 |
pipe = pipeline("image-to-text", model=model_id, model_kwargs={"quantization_config": quantization_config})
|
20 |
|
21 |
+
bodybuilding_criteria = {
|
22 |
+
"Muscular Size": "Focus on overall muscle mass and development.",
|
23 |
+
"Symmetry": "Ensure balanced development between left and right sides of the body.",
|
24 |
+
"Proportion": "Maintain aesthetically pleasing ratios between different muscle groups.",
|
25 |
+
"Definition": "Achieve clear separation between muscle groups and visible striations.",
|
26 |
+
"Conditioning": "Minimize body fat to enhance muscle definition and vascularity.",
|
27 |
+
"Posing": "Present physique effectively to highlight strengths and minimize weaknesses.",
|
28 |
+
}
|
29 |
+
|
30 |
+
bodybuilding_tips = [
|
31 |
+
"Train each muscle group at least twice a week for optimal growth.",
|
32 |
+
"Focus on compound exercises like squats, deadlifts, and bench presses for overall mass.",
|
33 |
+
"Don't neglect your legs! They're half your physique.",
|
34 |
+
"Proper nutrition is key. Eat clean and maintain a caloric surplus for growth.",
|
35 |
+
"Get enough rest. Muscles grow during recovery, not in the gym.",
|
36 |
+
"Practice your posing regularly. It's not just for shows, it helps mind-muscle connection.",
|
37 |
+
"Stay hydrated. Water is crucial for muscle function and recovery.",
|
38 |
+
]
|
39 |
+
|
40 |
def extract_response_pairs(text):
|
41 |
turns = re.split(r'(USER:|ASSISTANT:)', text)[1:]
|
42 |
turns = [turn.strip() for turn in turns if turn.strip()]
|
|
|
64 |
text = text.replace("exercise", "pump iron")
|
65 |
text = text.replace("workout", "sculpt your physique")
|
66 |
|
67 |
+
# Add bodybuilding advice
|
68 |
+
if random.random() < 0.7: # 70% chance to add bodybuilding advice
|
69 |
+
advice = random.choice(list(bodybuilding_criteria.items()))
|
70 |
+
text += f" Remember, in bodybuilding, {advice[0]} is crucial! {advice[1]}"
|
71 |
+
|
72 |
+
# Add a bodybuilding tip
|
73 |
+
if random.random() < 0.5: # 50% chance to add a tip
|
74 |
+
tip = random.choice(bodybuilding_tips)
|
75 |
+
text += f" Here's a pro tip: {tip}"
|
76 |
+
|
77 |
# Add random Arnold phrase to the end
|
78 |
text += " " + random.choice(arnold_phrases)
|
79 |
|
|
|
105 |
|
106 |
chat_history = " ".join([item for sublist in history for item in sublist if item is not None]) # Flatten history
|
107 |
|
108 |
+
if arnold_mode:
|
109 |
+
system_prompt = """You are Arnold Schwarzenegger, the famous bodybuilder, actor, and former Mr. Olympia.
|
110 |
+
Respond in his iconic style, using his catchphrases and focusing on fitness, bodybuilding, and motivation.
|
111 |
+
Incorporate bodybuilding judging criteria and tips in your responses when relevant."""
|
112 |
+
else:
|
113 |
+
system_prompt = "You are a helpful AI assistant. Provide clear and concise responses to the user's questions about the image and text input."
|
114 |
|
115 |
prompt = f"{system_prompt}\n{chat_history}\nUSER: <image>\n{text_input}\nASSISTANT:"
|
116 |
|
|
|
162 |
clear_button.click(lambda: ([], None), outputs=[chatbot, image], queue=False)
|
163 |
|
164 |
examples = [
|
165 |
+
["./examples/bodybuilder.jpg", "What do you think of this physique?"],
|
166 |
+
["./examples/gym.jpg", "How can I improve my workout routine?"]
|
167 |
]
|
168 |
gr.Examples(examples=examples, inputs=[image, text_input])
|
169 |
|