Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,35 @@ from supertonic import TTS
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import tempfile
|
| 5 |
import os
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Initialize the image-to-text pipeline
|
| 8 |
image_to_text = pipeline("image-to-text")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Initialize the TTS model
|
| 11 |
tts = TTS(auto_download=True)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Available voice styles (common Supertonic voices)
|
| 14 |
VOICE_OPTIONS = [
|
| 15 |
("M5 - Male Voice (Default)", "M5"),
|
|
@@ -68,6 +90,225 @@ def image_to_voice(image, voice_selection):
|
|
| 68 |
except Exception as e:
|
| 69 |
return None, f"β Error: {str(e)}"
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# Custom CSS for professional styling
|
| 72 |
custom_css = """
|
| 73 |
.gradio-container {
|
|
@@ -163,95 +404,286 @@ custom_css = """
|
|
| 163 |
"""
|
| 164 |
|
| 165 |
# Create Gradio interface
|
| 166 |
-
with gr.Blocks(title="
|
| 167 |
|
| 168 |
# Header Section
|
| 169 |
gr.HTML("""
|
| 170 |
<div class="header">
|
| 171 |
-
<h1>
|
| 172 |
-
<p>Transform images
|
| 173 |
</div>
|
| 174 |
""")
|
| 175 |
|
| 176 |
# Main Content Container
|
| 177 |
with gr.Column(elem_classes="main-content"):
|
| 178 |
|
| 179 |
-
#
|
| 180 |
-
with gr.
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
info="Choose a voice style for the generated audio"
|
| 221 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
)
|
| 229 |
|
| 230 |
-
#
|
| 231 |
-
with gr.
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
)
|
| 247 |
-
|
| 248 |
-
# Connection
|
| 249 |
-
generate_btn.click(
|
| 250 |
-
fn=image_to_voice,
|
| 251 |
-
inputs=[image_input, voice_dropdown],
|
| 252 |
-
outputs=[audio_output, text_output],
|
| 253 |
-
show_progress="full"
|
| 254 |
-
)
|
| 255 |
|
| 256 |
# Footer
|
| 257 |
gr.HTML("""
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import numpy as np
|
| 8 |
|
| 9 |
# Initialize the image-to-text pipeline
|
| 10 |
image_to_text = pipeline("image-to-text")
|
| 11 |
|
| 12 |
+
# Initialize text generation pipeline for story creation
|
| 13 |
+
text_generation = pipeline("text-generation", model="gpt2")
|
| 14 |
+
|
| 15 |
+
# Initialize Hugging Face image-to-text model for advanced story generation
|
| 16 |
+
try:
|
| 17 |
+
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
|
| 18 |
+
image_to_story_model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 19 |
+
image_feature_extractor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
|
| 20 |
+
image_to_story_tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 21 |
+
except:
|
| 22 |
+
image_to_story_model = None
|
| 23 |
+
image_feature_extractor = None
|
| 24 |
+
image_to_story_tokenizer = None
|
| 25 |
+
|
| 26 |
# Initialize the TTS model
|
| 27 |
tts = TTS(auto_download=True)
|
| 28 |
|
| 29 |
+
# Initialize emotion detection pipeline
|
| 30 |
+
try:
|
| 31 |
+
emotion_detection = pipeline("image-classification", model="nateraw/vit-base-beans")
|
| 32 |
+
except:
|
| 33 |
+
emotion_detection = None
|
| 34 |
+
|
| 35 |
# Available voice styles (common Supertonic voices)
|
| 36 |
VOICE_OPTIONS = [
|
| 37 |
("M5 - Male Voice (Default)", "M5"),
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
return None, f"β Error: {str(e)}"
|
| 92 |
|
| 93 |
+
def analyze_mood_from_image(image):
|
| 94 |
+
"""
|
| 95 |
+
Analyze mood/emotions detected in an image and create a mood chart.
|
| 96 |
+
|
| 97 |
+
Args:
|
| 98 |
+
image: Input image (PIL Image or numpy array)
|
| 99 |
+
|
| 100 |
+
Returns:
|
| 101 |
+
Chart data and mood analysis text
|
| 102 |
+
"""
|
| 103 |
+
if image is None:
|
| 104 |
+
return "Please upload an image.", {}
|
| 105 |
+
|
| 106 |
+
try:
|
| 107 |
+
# Simple mood detection based on color analysis
|
| 108 |
+
img_array = np.array(image)
|
| 109 |
+
|
| 110 |
+
# Calculate average colors
|
| 111 |
+
avg_brightness = np.mean(img_array)
|
| 112 |
+
avg_red = np.mean(img_array[:, :, 0]) if img_array.shape[2] > 0 else 0
|
| 113 |
+
avg_green = np.mean(img_array[:, :, 1]) if img_array.shape[2] > 1 else 0
|
| 114 |
+
avg_blue = np.mean(img_array[:, :, 2]) if img_array.shape[2] > 2 else 0
|
| 115 |
+
|
| 116 |
+
# Create mood mapping based on color analysis
|
| 117 |
+
mood_scores = {
|
| 118 |
+
"Happy": min(100, int((avg_brightness / 255 * 60) + (avg_yellow := (avg_red + avg_green) / 2 - avg_blue) / 2.55 * 40)),
|
| 119 |
+
"Calm": min(100, int((avg_blue / 255 * 50) + (avg_green / 255 * 50))),
|
| 120 |
+
"Energetic": min(100, int(avg_red / 255 * 100)),
|
| 121 |
+
"Peaceful": min(100, int((255 - avg_brightness) / 255 * 70 + avg_blue / 255 * 30)),
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
# Normalize scores
|
| 125 |
+
total = sum(mood_scores.values())
|
| 126 |
+
mood_scores = {k: int((v / total * 100)) for k, v in mood_scores.items()} if total > 0 else mood_scores
|
| 127 |
+
|
| 128 |
+
mood_text = f"""
|
| 129 |
+
**Mood Analysis Results:**
|
| 130 |
+
|
| 131 |
+
- π Happy: {mood_scores.get('Happy', 0)}%
|
| 132 |
+
- π Calm: {mood_scores.get('Calm', 0)}%
|
| 133 |
+
- β‘ Energetic: {mood_scores.get('Energetic', 0)}%
|
| 134 |
+
- π§ Peaceful: {mood_scores.get('Peaceful', 0)}%
|
| 135 |
+
|
| 136 |
+
**Interpretation:** Based on color analysis, this image conveys a {max(mood_scores, key=mood_scores.get)} mood.
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
return mood_text, mood_scores
|
| 140 |
+
except Exception as e:
|
| 141 |
+
return f"β Error analyzing mood: {str(e)}", {}
|
| 142 |
+
|
| 143 |
+
def ai_story_generation(image, story_theme):
|
| 144 |
+
"""
|
| 145 |
+
Generate a creative story based on the image content and selected theme.
|
| 146 |
+
|
| 147 |
+
Args:
|
| 148 |
+
image: Input image (PIL Image or numpy array)
|
| 149 |
+
story_theme: Selected theme for the story
|
| 150 |
+
|
| 151 |
+
Returns:
|
| 152 |
+
Generated story text
|
| 153 |
+
"""
|
| 154 |
+
if image is None:
|
| 155 |
+
return "Please upload an image to generate a story."
|
| 156 |
+
|
| 157 |
+
try:
|
| 158 |
+
# Extract text from image first
|
| 159 |
+
result = image_to_text(image)
|
| 160 |
+
image_description = result[0]['generated_text']
|
| 161 |
+
|
| 162 |
+
# Create a prompt for story generation
|
| 163 |
+
prompt = f"""Based on an image showing: {image_description}
|
| 164 |
+
|
| 165 |
+
Theme: {story_theme}
|
| 166 |
+
|
| 167 |
+
Generate a creative and engaging short story (150-200 words) incorporating elements from the image:"""
|
| 168 |
+
|
| 169 |
+
# Generate story using text generation pipeline
|
| 170 |
+
story = text_generation(prompt, max_length=250, num_return_sequences=1)
|
| 171 |
+
generated_story = story[0]['generated_text']
|
| 172 |
+
|
| 173 |
+
return generated_story
|
| 174 |
+
except Exception as e:
|
| 175 |
+
return f"β Error generating story: {str(e)}"
|
| 176 |
+
|
| 177 |
+
def huggingface_picture_to_story(image):
|
| 178 |
+
"""
|
| 179 |
+
Transform a picture into a story using Hugging Face image-to-text model.
|
| 180 |
+
Uses the specialized vit-gpt2-image-captioning model.
|
| 181 |
+
|
| 182 |
+
Args:
|
| 183 |
+
image: Input image (PIL Image or numpy array)
|
| 184 |
+
|
| 185 |
+
Returns:
|
| 186 |
+
Generated story based on image
|
| 187 |
+
"""
|
| 188 |
+
if image is None:
|
| 189 |
+
return "Please upload an image to generate a story."
|
| 190 |
+
|
| 191 |
+
try:
|
| 192 |
+
if image_to_story_model is None or image_feature_extractor is None:
|
| 193 |
+
return "Hugging Face story model not available. Using alternative method..."
|
| 194 |
+
|
| 195 |
+
# Prepare image
|
| 196 |
+
if isinstance(image, np.ndarray):
|
| 197 |
+
image = Image.fromarray(image)
|
| 198 |
+
|
| 199 |
+
# Extract features from image
|
| 200 |
+
pixel_values = image_feature_extractor(images=image, return_tensors="pt").pixel_values
|
| 201 |
+
|
| 202 |
+
# Generate story
|
| 203 |
+
output_ids = image_to_story_model.generate(pixel_values, max_length=100)
|
| 204 |
+
|
| 205 |
+
# Decode the generated text
|
| 206 |
+
story = image_to_story_tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
| 207 |
+
generated_story = story[0].strip() if story else "No story generated"
|
| 208 |
+
|
| 209 |
+
# Expand the basic caption into a more complete story
|
| 210 |
+
expanded_story = f"""
|
| 211 |
+
**AI-Generated Story from Image:**
|
| 212 |
+
|
| 213 |
+
{generated_story}
|
| 214 |
+
|
| 215 |
+
---
|
| 216 |
+
|
| 217 |
+
**Extended Story:**
|
| 218 |
+
|
| 219 |
+
In this captivating scene, {generated_story.lower()}. The image captures a moment of pure artistry and wonder,
|
| 220 |
+
where every detail tells a part of a larger narrative. As you observe the composition, your mind fills with possibilities
|
| 221 |
+
and untold stories waiting to be discovered. The interplay of light and shadow creates an atmosphere that invites
|
| 222 |
+
contemplation and imagination, transporting you to a world where reality meets fantasy.
|
| 223 |
+
"""
|
| 224 |
+
|
| 225 |
+
return expanded_story
|
| 226 |
+
except Exception as e:
|
| 227 |
+
return f"β Error generating story: {str(e)}"
|
| 228 |
+
|
| 229 |
+
def ai_study_helper(image, study_type):
|
| 230 |
+
"""
|
| 231 |
+
Provide AI-powered study insights based on image content.
|
| 232 |
+
|
| 233 |
+
Args:
|
| 234 |
+
image: Input image (PIL Image or numpy array)
|
| 235 |
+
study_type: Type of study aid requested
|
| 236 |
+
|
| 237 |
+
Returns:
|
| 238 |
+
Study insights and recommendations
|
| 239 |
+
"""
|
| 240 |
+
if image is None:
|
| 241 |
+
return "Please upload an image for study assistance."
|
| 242 |
+
|
| 243 |
+
try:
|
| 244 |
+
# Extract text from image
|
| 245 |
+
result = image_to_text(image)
|
| 246 |
+
extracted_text = result[0]['generated_text']
|
| 247 |
+
|
| 248 |
+
study_insights = ""
|
| 249 |
+
|
| 250 |
+
if study_type == "Summary":
|
| 251 |
+
study_insights = f"""
|
| 252 |
+
**AI-Generated Summary:**
|
| 253 |
+
|
| 254 |
+
{extracted_text[:200]}...
|
| 255 |
+
|
| 256 |
+
**Key Points:**
|
| 257 |
+
- Content extracted from image: {extracted_text}
|
| 258 |
+
- Length: {len(extracted_text.split())} words
|
| 259 |
+
- Recommended study time: {max(5, len(extracted_text.split()) // 100)} minutes
|
| 260 |
+
"""
|
| 261 |
+
elif study_type == "Quiz Questions":
|
| 262 |
+
study_insights = f"""
|
| 263 |
+
**AI-Generated Study Questions:**
|
| 264 |
+
|
| 265 |
+
Based on the image content: "{extracted_text[:100]}..."
|
| 266 |
+
|
| 267 |
+
1. What are the main topics covered in the image?
|
| 268 |
+
2. Can you explain the concepts in your own words?
|
| 269 |
+
3. How would you apply this information?
|
| 270 |
+
4. What are the key takeaways?
|
| 271 |
+
5. What additional research would enhance your understanding?
|
| 272 |
+
"""
|
| 273 |
+
elif study_type == "Learning Tips":
|
| 274 |
+
study_insights = f"""
|
| 275 |
+
**Personalized Learning Tips:**
|
| 276 |
+
|
| 277 |
+
π Study Strategy:
|
| 278 |
+
- Break down the content: {extracted_text[:50]}...
|
| 279 |
+
- Use the Feynman Technique to explain concepts simply
|
| 280 |
+
- Create mind maps for visual learning
|
| 281 |
+
- Practice active recall with the quiz questions feature
|
| 282 |
+
- Review regularly (spaced repetition)
|
| 283 |
+
|
| 284 |
+
π― Focus Areas:
|
| 285 |
+
- Main concept: Extract and understand key terms
|
| 286 |
+
- Relationships: Connect ideas together
|
| 287 |
+
- Application: Practice with real-world examples
|
| 288 |
+
"""
|
| 289 |
+
else: # Note-Taking
|
| 290 |
+
study_insights = f"""
|
| 291 |
+
**AI-Generated Study Notes:**
|
| 292 |
+
|
| 293 |
+
**Original Content:**
|
| 294 |
+
{extracted_text}
|
| 295 |
+
|
| 296 |
+
**Simplified Notes:**
|
| 297 |
+
- Main idea: {extracted_text[:80]}...
|
| 298 |
+
- Key details: Analyze and list important points
|
| 299 |
+
- Examples: Look for practical applications
|
| 300 |
+
- Conclusion: What did you learn?
|
| 301 |
+
|
| 302 |
+
**Action Items:**
|
| 303 |
+
β Review these notes daily
|
| 304 |
+
β Create flashcards for key terms
|
| 305 |
+
β Test yourself with quiz questions
|
| 306 |
+
"""
|
| 307 |
+
|
| 308 |
+
return study_insights
|
| 309 |
+
except Exception as e:
|
| 310 |
+
return f"β Error generating study insights: {str(e)}"
|
| 311 |
+
|
| 312 |
# Custom CSS for professional styling
|
| 313 |
custom_css = """
|
| 314 |
.gradio-container {
|
|
|
|
| 404 |
"""
|
| 405 |
|
| 406 |
# Create Gradio interface
|
| 407 |
+
with gr.Blocks(title="AI Multimedia Studio", theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 408 |
|
| 409 |
# Header Section
|
| 410 |
gr.HTML("""
|
| 411 |
<div class="header">
|
| 412 |
+
<h1>π¨ AI Multimedia Studio</h1>
|
| 413 |
+
<p>Transform images with AI-powered technology: voice, stories, mood analysis & study tools</p>
|
| 414 |
</div>
|
| 415 |
""")
|
| 416 |
|
| 417 |
# Main Content Container
|
| 418 |
with gr.Column(elem_classes="main-content"):
|
| 419 |
|
| 420 |
+
# Create tabs for different features
|
| 421 |
+
with gr.Tabs():
|
| 422 |
+
|
| 423 |
+
# ===== TAB 1: Image to Voice =====
|
| 424 |
+
with gr.TabItem("ποΈ Image to Voice"):
|
| 425 |
+
|
| 426 |
+
# Instructions Section
|
| 427 |
+
with gr.Row():
|
| 428 |
+
with gr.Column(scale=1):
|
| 429 |
+
gr.HTML("""
|
| 430 |
+
<div class="feature-box">
|
| 431 |
+
<h3>π· Step 1: Upload Image</h3>
|
| 432 |
+
<p>Upload any image containing text. Our AI will extract it automatically.</p>
|
| 433 |
+
</div>
|
| 434 |
+
""")
|
| 435 |
+
with gr.Column(scale=1):
|
| 436 |
+
gr.HTML("""
|
| 437 |
+
<div class="feature-box">
|
| 438 |
+
<h3>π€ Step 2: AI Processing</h3>
|
| 439 |
+
<p>Advanced vision-language models analyze and extract text from your image.</p>
|
| 440 |
+
</div>
|
| 441 |
+
""")
|
| 442 |
+
with gr.Column(scale=1):
|
| 443 |
+
gr.HTML("""
|
| 444 |
+
<div class="feature-box">
|
| 445 |
+
<h3>π Step 3: Audio Generation</h3>
|
| 446 |
+
<p>Text is converted to natural-sounding speech using Supertonic TTS.</p>
|
| 447 |
+
</div>
|
| 448 |
+
""")
|
| 449 |
+
|
| 450 |
+
# Main Workflow Section
|
| 451 |
+
with gr.Row():
|
| 452 |
+
# Left Column - Input
|
| 453 |
+
with gr.Column(scale=1, elem_classes="upload-section"):
|
| 454 |
+
gr.Markdown("### π€ Upload Your Image", elem_classes="section-title")
|
| 455 |
+
image_input = gr.Image(
|
| 456 |
+
label="",
|
| 457 |
+
type="pil",
|
| 458 |
+
height=350,
|
| 459 |
+
show_label=False
|
| 460 |
+
)
|
| 461 |
+
|
| 462 |
+
gr.Markdown("### ποΈ Voice Settings", elem_classes="section-title")
|
| 463 |
+
voice_dropdown = gr.Dropdown(
|
| 464 |
+
choices=[opt[0] for opt in VOICE_OPTIONS],
|
| 465 |
+
label="Select Voice Style",
|
| 466 |
+
value="M5 - Male Voice (Default)",
|
| 467 |
+
info="Choose a voice style for the generated audio"
|
| 468 |
+
)
|
| 469 |
+
|
| 470 |
+
generate_btn = gr.Button(
|
| 471 |
+
"β¨ Generate Audio",
|
| 472 |
+
variant="primary",
|
| 473 |
+
elem_classes="generate-btn",
|
| 474 |
+
size="lg"
|
| 475 |
+
)
|
| 476 |
+
|
| 477 |
+
# Right Column - Output
|
| 478 |
+
with gr.Column(scale=1, elem_classes="output-section"):
|
| 479 |
+
gr.Markdown("### π Extracted Text", elem_classes="section-title")
|
| 480 |
+
text_output = gr.Textbox(
|
| 481 |
+
label="",
|
| 482 |
+
lines=6,
|
| 483 |
+
show_label=False,
|
| 484 |
+
placeholder="The extracted text will appear here...",
|
| 485 |
+
interactive=False
|
| 486 |
+
)
|
| 487 |
+
|
| 488 |
+
gr.Markdown("### π Generated Audio", elem_classes="section-title")
|
| 489 |
+
audio_output = gr.Audio(
|
| 490 |
+
label="",
|
| 491 |
+
type="filepath",
|
| 492 |
+
show_label=False
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
+
# Connection
|
| 496 |
+
generate_btn.click(
|
| 497 |
+
fn=image_to_voice,
|
| 498 |
+
inputs=[image_input, voice_dropdown],
|
| 499 |
+
outputs=[audio_output, text_output],
|
| 500 |
+
show_progress="full"
|
| 501 |
)
|
| 502 |
+
|
| 503 |
+
# ===== TAB 2: Mood Chart =====
|
| 504 |
+
with gr.TabItem("π Mood Chart"):
|
| 505 |
+
|
| 506 |
+
with gr.Row():
|
| 507 |
+
with gr.Column(scale=1):
|
| 508 |
+
gr.Markdown("### π€ Upload Your Image", elem_classes="section-title")
|
| 509 |
+
mood_image_input = gr.Image(
|
| 510 |
+
label="",
|
| 511 |
+
type="pil",
|
| 512 |
+
height=350,
|
| 513 |
+
show_label=False
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
mood_analyze_btn = gr.Button(
|
| 517 |
+
"π Analyze Mood",
|
| 518 |
+
variant="primary",
|
| 519 |
+
elem_classes="generate-btn",
|
| 520 |
+
size="lg"
|
| 521 |
+
)
|
| 522 |
+
|
| 523 |
+
with gr.Column(scale=1):
|
| 524 |
+
gr.Markdown("### π Mood Analysis Results", elem_classes="section-title")
|
| 525 |
+
mood_output = gr.Textbox(
|
| 526 |
+
label="",
|
| 527 |
+
lines=10,
|
| 528 |
+
show_label=False,
|
| 529 |
+
placeholder="Mood analysis will appear here...",
|
| 530 |
+
interactive=False
|
| 531 |
+
)
|
| 532 |
|
| 533 |
+
mood_analyze_btn.click(
|
| 534 |
+
fn=analyze_mood_from_image,
|
| 535 |
+
inputs=[mood_image_input],
|
| 536 |
+
outputs=[mood_output],
|
| 537 |
+
show_progress="full"
|
|
|
|
| 538 |
)
|
| 539 |
+
|
| 540 |
+
# ===== TAB 3: Story Generation =====
|
| 541 |
+
with gr.TabItem("π AI Story Generator"):
|
| 542 |
+
|
| 543 |
+
with gr.Row():
|
| 544 |
+
with gr.Column(scale=1):
|
| 545 |
+
gr.Markdown("### π€ Upload Your Image", elem_classes="section-title")
|
| 546 |
+
story_image_input = gr.Image(
|
| 547 |
+
label="",
|
| 548 |
+
type="pil",
|
| 549 |
+
height=350,
|
| 550 |
+
show_label=False
|
| 551 |
+
)
|
| 552 |
+
|
| 553 |
+
gr.Markdown("### π Story Theme", elem_classes="section-title")
|
| 554 |
+
story_theme_dropdown = gr.Dropdown(
|
| 555 |
+
choices=[
|
| 556 |
+
"Adventure",
|
| 557 |
+
"Fantasy",
|
| 558 |
+
"Mystery",
|
| 559 |
+
"Romance",
|
| 560 |
+
"Science Fiction",
|
| 561 |
+
"Comedy",
|
| 562 |
+
"Educational",
|
| 563 |
+
"Inspirational"
|
| 564 |
+
],
|
| 565 |
+
label="Select Story Theme",
|
| 566 |
+
value="Adventure",
|
| 567 |
+
info="Choose a theme for your story"
|
| 568 |
+
)
|
| 569 |
+
|
| 570 |
+
story_generate_btn = gr.Button(
|
| 571 |
+
"βοΈ Generate Story",
|
| 572 |
+
variant="primary",
|
| 573 |
+
elem_classes="generate-btn",
|
| 574 |
+
size="lg"
|
| 575 |
+
)
|
| 576 |
+
|
| 577 |
+
with gr.Column(scale=1):
|
| 578 |
+
gr.Markdown("### π Generated Story", elem_classes="section-title")
|
| 579 |
+
story_output = gr.Textbox(
|
| 580 |
+
label="",
|
| 581 |
+
lines=12,
|
| 582 |
+
show_label=False,
|
| 583 |
+
placeholder="Your story will appear here...",
|
| 584 |
+
interactive=False
|
| 585 |
+
)
|
| 586 |
|
| 587 |
+
story_generate_btn.click(
|
| 588 |
+
fn=ai_story_generation,
|
| 589 |
+
inputs=[story_image_input, story_theme_dropdown],
|
| 590 |
+
outputs=[story_output],
|
| 591 |
+
show_progress="full"
|
| 592 |
)
|
| 593 |
|
| 594 |
+
# ===== TAB 3B: Hugging Face Picture to Story =====
|
| 595 |
+
with gr.TabItem("π¨ HuggingFace Picture to Story"):
|
| 596 |
+
|
| 597 |
+
gr.Markdown("""
|
| 598 |
+
### π€ Advanced AI Story Generation using Hugging Face
|
| 599 |
+
|
| 600 |
+
This feature uses the cutting-edge **Vision Transformer (ViT) + GPT-2** model from Hugging Face
|
| 601 |
+
to directly transform your picture into a creative narrative story.
|
| 602 |
+
""")
|
| 603 |
+
|
| 604 |
+
with gr.Row():
|
| 605 |
+
with gr.Column(scale=1):
|
| 606 |
+
gr.Markdown("### π€ Upload Your Picture", elem_classes="section-title")
|
| 607 |
+
hf_story_image_input = gr.Image(
|
| 608 |
+
label="",
|
| 609 |
+
type="pil",
|
| 610 |
+
height=350,
|
| 611 |
+
show_label=False
|
| 612 |
+
)
|
| 613 |
+
|
| 614 |
+
hf_story_generate_btn = gr.Button(
|
| 615 |
+
"π Transform to Story",
|
| 616 |
+
variant="primary",
|
| 617 |
+
elem_classes="generate-btn",
|
| 618 |
+
size="lg"
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
with gr.Column(scale=1):
|
| 622 |
+
gr.Markdown("### π AI-Generated Story", elem_classes="section-title")
|
| 623 |
+
hf_story_output = gr.Textbox(
|
| 624 |
+
label="",
|
| 625 |
+
lines=14,
|
| 626 |
+
show_label=False,
|
| 627 |
+
placeholder="Your AI story will appear here...",
|
| 628 |
+
interactive=False
|
| 629 |
+
)
|
| 630 |
+
|
| 631 |
+
hf_story_generate_btn.click(
|
| 632 |
+
fn=huggingface_picture_to_story,
|
| 633 |
+
inputs=[hf_story_image_input],
|
| 634 |
+
outputs=[hf_story_output],
|
| 635 |
+
show_progress="full"
|
| 636 |
)
|
| 637 |
+
|
| 638 |
+
# ===== TAB 4: Study Helper =====
|
| 639 |
+
with gr.TabItem("π AI Study Helper"):
|
| 640 |
+
|
| 641 |
+
with gr.Row():
|
| 642 |
+
with gr.Column(scale=1):
|
| 643 |
+
gr.Markdown("### π€ Upload Your Study Material", elem_classes="section-title")
|
| 644 |
+
study_image_input = gr.Image(
|
| 645 |
+
label="",
|
| 646 |
+
type="pil",
|
| 647 |
+
height=350,
|
| 648 |
+
show_label=False
|
| 649 |
+
)
|
| 650 |
+
|
| 651 |
+
gr.Markdown("### π― Study Assistance Type", elem_classes="section-title")
|
| 652 |
+
study_type_dropdown = gr.Dropdown(
|
| 653 |
+
choices=[
|
| 654 |
+
"Summary",
|
| 655 |
+
"Quiz Questions",
|
| 656 |
+
"Learning Tips",
|
| 657 |
+
"Note-Taking"
|
| 658 |
+
],
|
| 659 |
+
label="Select Study Aid",
|
| 660 |
+
value="Summary",
|
| 661 |
+
info="Choose the type of study assistance you need"
|
| 662 |
+
)
|
| 663 |
+
|
| 664 |
+
study_generate_btn = gr.Button(
|
| 665 |
+
"π Generate Study Aid",
|
| 666 |
+
variant="primary",
|
| 667 |
+
elem_classes="generate-btn",
|
| 668 |
+
size="lg"
|
| 669 |
+
)
|
| 670 |
+
|
| 671 |
+
with gr.Column(scale=1):
|
| 672 |
+
gr.Markdown("### π Study Insights", elem_classes="section-title")
|
| 673 |
+
study_output = gr.Textbox(
|
| 674 |
+
label="",
|
| 675 |
+
lines=12,
|
| 676 |
+
show_label=False,
|
| 677 |
+
placeholder="Study insights will appear here...",
|
| 678 |
+
interactive=False
|
| 679 |
+
)
|
| 680 |
|
| 681 |
+
study_generate_btn.click(
|
| 682 |
+
fn=ai_study_helper,
|
| 683 |
+
inputs=[study_image_input, study_type_dropdown],
|
| 684 |
+
outputs=[study_output],
|
| 685 |
+
show_progress="full"
|
| 686 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 687 |
|
| 688 |
# Footer
|
| 689 |
gr.HTML("""
|