Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- .gradio/certificate.pem +31 -0
- DoomScroller_Analizer.ipynb +0 -0
- README.md +4 -9
- deploy.py +218 -0
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
| 7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
| 8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
| 9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
| 10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
| 11 |
+
T8KOEUt+zw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jFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
DoomScroller_Analizer.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
CHANGED
|
@@ -1,12 +1,7 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Insagram_reel_Analyzer
|
| 3 |
+
app_file: deploy.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 5.31.0
|
|
|
|
|
|
|
| 6 |
---
|
| 7 |
+
# Doom_Scroller_Instagram
|
|
|
deploy.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io # Import io for handling image bytes
|
| 2 |
+
|
| 3 |
+
# Global variables to maintain state across Gradio calls
|
| 4 |
+
# Assuming cl and explore_reels_list are already defined and populated by login/fetch steps
|
| 5 |
+
# from previous cells in a real execution environment.
|
| 6 |
+
# For this cell's context, we ensure they are declared global.
|
| 7 |
+
global cl
|
| 8 |
+
global explore_reels_list
|
| 9 |
+
global sentiment_analyzer_instance
|
| 10 |
+
global content_classifier_pipeline
|
| 11 |
+
|
| 12 |
+
# Initialize sentiment analyzer if not already done (can be done here or lazily in analyze_reels_gradio)
|
| 13 |
+
# Doing it here ensures the model is loaded when this cell runs, potentially reducing latency on first analyze click.
|
| 14 |
+
try:
|
| 15 |
+
sentiment_analyzer_instance = ReelSentimentAnalyzer()
|
| 16 |
+
print("Sentiment Analyzer initialized.")
|
| 17 |
+
# Optional: Train Hindi model if needed and data is available
|
| 18 |
+
# sample_train_data = [...] # Define your training data
|
| 19 |
+
# sentiment_analyzer_instance.train_hindi_model(sample_train_data)
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"Error initializing Sentiment Analyzer globally: {e}")
|
| 22 |
+
sentiment_analyzer_instance = None
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# Initialize content classifier pipeline if not already done (can be done here or lazily)
|
| 26 |
+
try:
|
| 27 |
+
print("Initializing Content Classifier Pipeline globally...")
|
| 28 |
+
content_classifier_pipeline = pipeline(
|
| 29 |
+
"zero-shot-classification",
|
| 30 |
+
model="facebook/bart-large-mnli",
|
| 31 |
+
device=0 if torch.cuda.is_available() else -1 # Use GPU if available
|
| 32 |
+
)
|
| 33 |
+
print("Content Classifier Pipeline Initialized.")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Error initializing Content Classifier globally: {e}")
|
| 36 |
+
content_classifier_pipeline = None
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def analyze_reels_gradio(max_to_analyze):
|
| 40 |
+
"""Gradio-compatible function to analyze fetched reels and generate plots."""
|
| 41 |
+
global explore_reels_list
|
| 42 |
+
global sentiment_analyzer_instance
|
| 43 |
+
global content_classifier_pipeline
|
| 44 |
+
|
| 45 |
+
if not explore_reels_list:
|
| 46 |
+
# Return None for plots if no reels
|
| 47 |
+
return "Error: No reels fetched yet. Please fetch reels first.", None, None
|
| 48 |
+
|
| 49 |
+
# Ensure max_to_analyze does not exceed the number of fetched reels
|
| 50 |
+
num_reels_to_process = min(max_to_analyze, len(explore_reels_list))
|
| 51 |
+
reels_to_analyze = explore_reels_list[:num_reels_to_process]
|
| 52 |
+
|
| 53 |
+
if not reels_to_analyze:
|
| 54 |
+
return "Error: No reels available to analyze.", None, None
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Check if analyzers are initialized
|
| 58 |
+
if sentiment_analyzer_instance is None:
|
| 59 |
+
return "Error: Sentiment Analyzer not initialized.", None, None
|
| 60 |
+
if content_classifier_pipeline is None:
|
| 61 |
+
return "Error: Content Classifier not initialized.", None, None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
analysis_status_messages = []
|
| 65 |
+
sentiment_plot_figure = None # Changed to figure
|
| 66 |
+
content_plot_figure = None # Changed to figure
|
| 67 |
+
|
| 68 |
+
# Perform Sentiment Analysis
|
| 69 |
+
try:
|
| 70 |
+
analysis_status_messages.append(f"Starting Sentiment Analysis for {len(reels_to_analyze)} reels...")
|
| 71 |
+
sentiment_results, detailed_sentiment_results = sentiment_analyzer_instance.analyze_reels(
|
| 72 |
+
reels_to_analyze,
|
| 73 |
+
max_to_analyze=len(reels_to_analyze) # Pass the actual number being processed
|
| 74 |
+
)
|
| 75 |
+
# Call the updated plotting function that returns a figure
|
| 76 |
+
sentiment_plot_figure = plot_sentiment_pie(sentiment_results, title=f"Sentiment of {len(reels_to_analyze)} Instagram Reels")
|
| 77 |
+
analysis_status_messages.append("Sentiment Analysis Complete.")
|
| 78 |
+
except Exception as e:
|
| 79 |
+
analysis_status_messages.append(f"Error during Sentiment Analysis: {e}")
|
| 80 |
+
sentiment_plot_figure = None # Ensure plot is None on error
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# Perform Content Categorization
|
| 84 |
+
try:
|
| 85 |
+
analysis_status_messages.append(f"Starting Content Categorization for {len(reels_to_analyze)} reels...")
|
| 86 |
+
category_counts = Counter()
|
| 87 |
+
# Re-implement content analysis slightly to fit this flow using the global pipeline
|
| 88 |
+
print(f"\n⏳ Analyzing content for {len(reels_to_analyze)} reels...")
|
| 89 |
+
for i, reel in enumerate(reels_to_analyze, 1):
|
| 90 |
+
caption = getattr(reel, 'caption_text', '') or getattr(reel, 'caption', '') or ''
|
| 91 |
+
# Use the global classifier pipeline
|
| 92 |
+
category, details = classify_reel_content(caption)
|
| 93 |
+
category_counts[category] += 1
|
| 94 |
+
|
| 95 |
+
print("\n✅ Content Analysis complete!")
|
| 96 |
+
print("\n📊 Category Counts:")
|
| 97 |
+
for category, count in category_counts.most_common():
|
| 98 |
+
print(f"- {category.replace('_', ' ').title()}: {count}")
|
| 99 |
+
|
| 100 |
+
# Call the updated plotting function that returns a figure
|
| 101 |
+
content_plot_figure = plot_category_distribution(category_counts)
|
| 102 |
+
analysis_status_messages.append("Content Categorization Complete.")
|
| 103 |
+
|
| 104 |
+
except Exception as e:
|
| 105 |
+
analysis_status_messages.append(f"Error during Content Analysis: {e}")
|
| 106 |
+
content_plot_figure = None # Ensure plot is None on error
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
final_status_message = "\n".join(analysis_status_messages)
|
| 110 |
+
# Return the figure objects
|
| 111 |
+
return final_status_message, sentiment_plot_figure, content_plot_figure
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
# Re-define plot functions to return bytes (if not already done in a previous cell)
|
| 115 |
+
# Assuming they were defined in the previous subtask's code block.
|
| 116 |
+
# If not, they would need to be included here.
|
| 117 |
+
|
| 118 |
+
# --- Gradio Blocks Interface ---
|
| 119 |
+
with gr.Blocks() as demo:
|
| 120 |
+
gr.Markdown("# Instagram Reels Analysis")
|
| 121 |
+
with gr.Row():
|
| 122 |
+
username_input = gr.Textbox(label="Instagram Username")
|
| 123 |
+
login_button = gr.Button("Login")
|
| 124 |
+
login_status_output = gr.Label(label="Login Status")
|
| 125 |
+
|
| 126 |
+
with gr.Row():
|
| 127 |
+
fetch_button = gr.Button("Fetch Reels")
|
| 128 |
+
fetch_status_output = gr.Label(label="Fetch Status")
|
| 129 |
+
|
| 130 |
+
with gr.Row():
|
| 131 |
+
max_reels_input = gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Number of Reels to Analyze")
|
| 132 |
+
analyze_button = gr.Button("Analyze Reels")
|
| 133 |
+
|
| 134 |
+
analyze_status_output = gr.Label(label="Analysis Status")
|
| 135 |
+
|
| 136 |
+
with gr.Row():
|
| 137 |
+
# Sentiment Analysis Outputs
|
| 138 |
+
with gr.Column():
|
| 139 |
+
gr.Markdown("## Sentiment Analysis")
|
| 140 |
+
sentiment_plot_output = gr.Plot(label="Sentiment Distribution")
|
| 141 |
+
|
| 142 |
+
# Content Analysis Outputs
|
| 143 |
+
with gr.Column():
|
| 144 |
+
gr.Markdown("## Content Analysis")
|
| 145 |
+
content_plot_output = gr.Plot(label="Content Distribution")
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
# Link login and fetch buttons (assuming login_gradio and fetch_reels_gradio are defined)
|
| 149 |
+
# Redefine login_gradio and fetch_reels_gradio here within the Blocks context
|
| 150 |
+
# to ensure they are linked correctly, even though they were defined above.
|
| 151 |
+
# This is a common pattern in Gradio Blocks.
|
| 152 |
+
|
| 153 |
+
def login_gradio_blocks(username):
|
| 154 |
+
"""Gradio-compatible login function for Blocks."""
|
| 155 |
+
global cl
|
| 156 |
+
try:
|
| 157 |
+
PASSWORD = userdata.get('password')
|
| 158 |
+
except Exception as e:
|
| 159 |
+
return f"Error accessing password secret: {e}"
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
if not PASSWORD:
|
| 163 |
+
return "Error: Instagram password not found in Colab secrets."
|
| 164 |
+
|
| 165 |
+
cl = Client()
|
| 166 |
+
|
| 167 |
+
try:
|
| 168 |
+
cl.login(username, PASSWORD)
|
| 169 |
+
return f"Successfully logged in as {username}"
|
| 170 |
+
except Exception as e:
|
| 171 |
+
cl = None # Ensure cl is None on failure
|
| 172 |
+
return f"Error during login: {e}"
|
| 173 |
+
|
| 174 |
+
def fetch_reels_gradio_blocks():
|
| 175 |
+
"""Gradio-compatible function to fetch explore reels for Blocks."""
|
| 176 |
+
global cl
|
| 177 |
+
global explore_reels_list
|
| 178 |
+
|
| 179 |
+
if cl is None:
|
| 180 |
+
explore_reels_list = [] # Ensure list is empty on failure
|
| 181 |
+
return "Error: Not logged in. Please log in first."
|
| 182 |
+
|
| 183 |
+
try:
|
| 184 |
+
# Fetch a limited number of reels for demonstration purposes
|
| 185 |
+
# You might want to make this number configurable later
|
| 186 |
+
fetched_reels = cl.explore_reels()[:100] # Fetch up to 100 for analysis
|
| 187 |
+
explore_reels_list = fetched_reels
|
| 188 |
+
if explore_reels_list:
|
| 189 |
+
return f"Successfully fetched {len(explore_reels_list)} explore reels."
|
| 190 |
+
else:
|
| 191 |
+
explore_reels_list = [] # Ensure it's an empty list
|
| 192 |
+
return "Fetched 0 explore reels."
|
| 193 |
+
except Exception as e:
|
| 194 |
+
explore_reels_list = [] # Ensure it's an empty list on error
|
| 195 |
+
return f"Error fetching explore reels: {e}"
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
login_button.click(
|
| 199 |
+
fn=login_gradio_blocks,
|
| 200 |
+
inputs=username_input,
|
| 201 |
+
outputs=login_status_output
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
fetch_button.click(
|
| 205 |
+
fn=fetch_reels_gradio_blocks,
|
| 206 |
+
inputs=None, # No direct inputs needed for fetching
|
| 207 |
+
outputs=fetch_status_output
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
# Link the Analyze button to the analysis function
|
| 211 |
+
analyze_button.click(
|
| 212 |
+
fn=analyze_reels_gradio,
|
| 213 |
+
inputs=max_reels_input, # Input is the slider value
|
| 214 |
+
outputs=[analyze_status_output, sentiment_plot_output, content_plot_output] # Outputs are status and the two plots
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
# The demo is now fully defined. It can be launched in the next step.
|
| 218 |
+
# demo.launch()
|