Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,95 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import spacy
|
| 3 |
-
from transformers import pipeline
|
| 4 |
-
import json
|
| 5 |
-
|
| 6 |
-
# Load models once at startup
|
| 7 |
-
nlp = spacy.load("en_core_web_sm")
|
| 8 |
-
classifier = pipeline("zero-shot-classification")
|
| 9 |
-
|
| 10 |
-
def analyze_script(script):
|
| 11 |
-
"""4-Layer Script Analysis"""
|
| 12 |
-
if not script.strip():
|
| 13 |
-
return "β Please enter a script to analyze"
|
| 14 |
-
|
| 15 |
-
try:
|
| 16 |
-
# Layer 1: Keywords
|
| 17 |
-
doc = nlp(script.lower())
|
| 18 |
-
transformation_words = ['struggle', 'problem', 'challenge', 'change', 'transform', 'before', 'after', 'frustrat', 'difficult']
|
| 19 |
-
explanation_words = ['show', 'teach', 'explain', 'demonstrate', 'process', 'method', 'step', 'guide', 'walk']
|
| 20 |
-
authority_words = ['discover', 'find', 'learn', 'experience', 'proven', 'tested', 'years', 'expert']
|
| 21 |
-
|
| 22 |
-
keywords = {
|
| 23 |
-
'transformation': list(set([token.text for token in doc if token.lemma_ in transformation_words])),
|
| 24 |
-
'explanation': list(set([token.text for token in doc if token.lemma_ in explanation_words])),
|
| 25 |
-
'authority': list(set([token.text for token in doc if token.lemma_ in authority_words]))
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
# Layer 2: Semantics
|
| 29 |
-
concepts = []
|
| 30 |
-
for sent in doc.sents:
|
| 31 |
-
sent_text = sent.text.lower()
|
| 32 |
-
if any(word in sent_text for word in ['struggle', 'problem', 'difficult', 'frustrat']):
|
| 33 |
-
concepts.append("PAIN_POINT")
|
| 34 |
-
if any(word in sent_text for word in ['discover', 'find', 'figure out', 'learn']):
|
| 35 |
-
concepts.append("SOLUTION_DISCOVERY")
|
| 36 |
-
if any(word in sent_text for word in ['change', 'transform', 'better', 'improve']):
|
| 37 |
-
concepts.append("TRANSFORMATION_RESULT")
|
| 38 |
-
if any(word in sent_text for word in ['show', 'teach', 'explain', 'demonstrate']):
|
| 39 |
-
concepts.append("TEACHING_PROMISE")
|
| 40 |
-
|
| 41 |
-
# Layer 3: Narrative
|
| 42 |
-
narrative = []
|
| 43 |
-
for sent in doc.sents:
|
| 44 |
-
sent_lower = sent.text.lower()
|
| 45 |
-
if any(word in sent_lower for word in ['struggle', 'problem', 'difficult']):
|
| 46 |
-
narrative.append("PROBLEM_STATEMENT")
|
| 47 |
-
elif any(word in sent_lower for word in ['discover', 'find', 'figure out']):
|
| 48 |
-
narrative.append("SOLUTION_DISCOVERY")
|
| 49 |
-
elif any(word in sent_lower for word in ['show', 'teach', 'explain']):
|
| 50 |
-
narrative.append("TEACHING_PROMISE")
|
| 51 |
-
elif any(word in sent_lower for word in ['change', 'transform', 'better']):
|
| 52 |
-
narrative.append("TRANSFORMATION_RESULT")
|
| 53 |
-
else:
|
| 54 |
-
narrative.append("CONTEXT")
|
| 55 |
-
|
| 56 |
-
# Layer 4: Intent
|
| 57 |
-
intent = classifier(script, ["transformation", "explanation", "authority", "entertainment"])
|
| 58 |
-
|
| 59 |
-
# Format results
|
| 60 |
-
result = f"""
|
| 61 |
-
π― **SCRIPT ANALYSIS RESULTS**
|
| 62 |
-
|
| 63 |
-
π **KEYWORDS:**
|
| 64 |
-
- Transformation: {', '.join(keywords['transformation']) if keywords['transformation'] else 'None'}
|
| 65 |
-
- Explanation: {', '.join(keywords['explanation']) if keywords['explanation'] else 'None'}
|
| 66 |
-
- Authority: {', '.join(keywords['authority']) if keywords['authority'] else 'None'}
|
| 67 |
-
|
| 68 |
-
π§ **CONCEPTS:** {', '.join(set(concepts))}
|
| 69 |
-
|
| 70 |
-
π **NARRATIVE FLOW:** {' β '.join(narrative)}
|
| 71 |
-
|
| 72 |
-
π **PRIMARY INTENT:** {intent['labels'][0]} ({intent['scores'][0]:.1%} confidence)
|
| 73 |
-
|
| 74 |
-
π **STATS:** {len(list(doc.sents))} sentences, {len([t for t in doc if t.is_alpha])} words
|
| 75 |
-
"""
|
| 76 |
-
return result
|
| 77 |
-
|
| 78 |
-
except Exception as e:
|
| 79 |
-
return f"β Error analyzing script: {str(e)}"
|
| 80 |
-
|
| 81 |
-
# Create Gradio interface
|
| 82 |
-
demo = gr.Interface(
|
| 83 |
-
fn=analyze_script,
|
| 84 |
-
inputs=gr.Textbox(lines=10, placeholder="Paste your script here...", label="Script"),
|
| 85 |
-
outputs=gr.Textbox(label="Analysis Results"),
|
| 86 |
-
title="π€ Script Analyzer Pro",
|
| 87 |
-
description="4-Layer Analysis: Keywords β Semantics β Narrative β Intent"
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
# For API access
|
| 91 |
-
def api_analyze(script):
|
| 92 |
-
return analyze_script(script)
|
| 93 |
-
|
| 94 |
-
if __name__ == "__main__":
|
| 95 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|