miguelcastroe commited on
Commit
30ae471
·
verified ·
1 Parent(s): a75bc1e

Upload folder using huggingface_hub

Browse files
.github/workflows/update_space.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run Python script
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v2
18
+ with:
19
+ python-version: '3.9'
20
+
21
+ - name: Install Gradio
22
+ run: python -m pip install gradio
23
+
24
+ - name: Log in to Hugging Face
25
+ run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
26
+
27
+ - name: Deploy to Spaces
28
+ run: gradio deploy
.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/vVqbvYATyjb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CgKQ5
24
+ ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
25
+ TkXWStAmzOVyyghqpZXjFaH3pO3JLF+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-----
Musical Arc/44badc0663277c7b4461/emotional_music_arc.png RENAMED
File without changes
.gradio/flagged/dataset1.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ script,Analysis Results,Emotional and Musical Arc,timestamp
2
+ "A year from now we'll all be gone, all our friends will move away and they're going to better places.","**Line 1:**
3
+ A year from now we'll all be gone, all our friends will move away and they're going to better places.
4
+ Sentiment: POSITIVE (Score: 0.99)
5
+ Scene Description: A warm glow fills the air, carrying a sense of joy and peace.
6
+ Music Cue: Soft, uplifting melody with bright piano notes.
7
+ ",.gradio/flagged/Emotional and Musical Arc/44badc0663277c7b4461/emotional_music_arc.png,2024-11-07 19:37:06.048168
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
  title: VisionFlow
3
- emoji: 🚀
4
- colorFrom: pink
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 5.5.0
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: VisionFlow
3
+ app_file: script_analyzer.py
 
 
4
  sdk: gradio
5
  sdk_version: 5.5.0
 
 
6
  ---
 
 
emotional_music_arc.png ADDED
script_analyzer.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer, AutoModelForCausalLM
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Load advanced sentiment analysis model
6
+ tokenizer_sentiment = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
7
+ model_sentiment = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
8
+ sentiment_classifier = pipeline("sentiment-analysis", model=model_sentiment, tokenizer=tokenizer_sentiment)
9
+
10
+ # Load open-source language model for description and music cue generation (GPT-J or GPT-Neo)
11
+ tokenizer_gpt = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-2.7B")
12
+ model_gpt = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-2.7B")
13
+
14
+ # Helper function to generate text using GPT-Neo or GPT-J
15
+ def generate_text(prompt):
16
+ inputs = tokenizer_gpt(prompt, return_tensors="pt", truncation=True, max_length=50)
17
+ outputs = model_gpt.generate(inputs["input_ids"], max_length=50, num_return_sequences=1, no_repeat_ngram_size=2)
18
+ generated_text = tokenizer_gpt.decode(outputs[0], skip_special_tokens=True)
19
+ return generated_text.strip()
20
+
21
+ # Function to analyze each line of the script
22
+ def analyze_script(script):
23
+ global all_scores, descriptions, music_cues
24
+ lines = script.strip().split("\n")
25
+ all_scores = []
26
+ descriptions = []
27
+ music_cues = []
28
+ analysis_results = []
29
+
30
+ for i, line in enumerate(lines):
31
+ # Perform sentiment analysis with advanced model
32
+ result = sentiment_classifier(line)[0]
33
+ sentiment = result['label']
34
+ score = result['score']
35
+
36
+ # Generate a detailed scene description based on sentiment and line content
37
+ description_prompt = f"Describe a scene with the sentiment '{sentiment}' for the line: '{line}'"
38
+ description = generate_text(description_prompt)
39
+
40
+ # Generate a specific music cue suggestion based on sentiment
41
+ music_cue_prompt = f"Suggest music elements (like tempo, key, and instrumentation) that would fit a scene with the sentiment '{sentiment}': '{line}'"
42
+ music_cue = generate_text(music_cue_prompt)
43
+
44
+ # Append data for display and graph
45
+ all_scores.append(score)
46
+ descriptions.append(description)
47
+ music_cues.append(music_cue)
48
+
49
+ # Format analysis results
50
+ analysis_results.append(
51
+ {
52
+ "Line": f"Line {i + 1}: {line}",
53
+ "Sentiment": f"{sentiment} (Score: {round(score, 2)})",
54
+ "Description Suggestion": description,
55
+ "Music Cue": music_cue
56
+ }
57
+ )
58
+
59
+ # Generate the emotional arc graph for the entire script
60
+ graph_path = generate_script_graph()
61
+ return analysis_results, graph_path
62
+
63
+ # Generate the emotional arc graph with music cues for the entire script
64
+ def generate_script_graph():
65
+ plt.figure(figsize=(12, 6))
66
+ plt.plot(all_scores, marker='o', linestyle='-', color='b', label='Sentiment Intensity')
67
+
68
+ # Add text labels for music cues along the graph
69
+ for i, score in enumerate(all_scores):
70
+ plt.text(i, score, music_cues[i], fontsize=8, ha='right', rotation=45)
71
+
72
+ plt.title('Emotional and Musical Arc for Entire Script')
73
+ plt.xlabel('Script Lines (Accumulative)')
74
+ plt.ylabel('Sentiment Intensity')
75
+ plt.legend()
76
+ plt.tight_layout()
77
+
78
+ # Save plot as image file
79
+ plot_path = "script_emotional_arc.png"
80
+ plt.savefig(plot_path)
81
+ plt.close()
82
+ return plot_path
83
+
84
+ # Custom Gradio component to display dashboard results with icons
85
+ def format_dashboard(results):
86
+ formatted_results = ""
87
+ for result in results:
88
+ formatted_results += f"""
89
+ <div style="border:1px solid #ddd; padding:10px; margin-bottom:10px; border-radius:5px;">
90
+ <p>🎬 <strong>{result['Line']}</strong></p>
91
+ <p>📊 <strong>Sentiment:</strong> {result['Sentiment']}</p>
92
+ <p>💡 <strong>Description Suggestion:</strong> {result['Description Suggestion']}</p>
93
+ <p>🎶 <strong>Music Cue:</strong> {result['Music Cue']}</p>
94
+ </div>
95
+ """
96
+ return formatted_results
97
+
98
+ # Gradio interface to analyze script and display the dashboard
99
+ with gr.Blocks() as interface:
100
+ gr.Markdown("## Script Sentiment and Music Cue Analyzer")
101
+ gr.Markdown("Enter your script line-by-line, and this tool will analyze sentiment, generate scene descriptions, suggest music cues, and show an emotional and musical arc.")
102
+
103
+ script_input = gr.Textbox(lines=10, placeholder="Enter your script here, one line per thought or dialogue.", label="Script")
104
+ display_dashboard_button = gr.Button("Analyze Script")
105
+
106
+ output_dashboard = gr.HTML(label="Dashboard Results")
107
+ output_graph = gr.Image(label="Emotional and Musical Arc for Entire Script")
108
+
109
+ # Display dashboard functionality
110
+ def display_dashboard(script):
111
+ analysis_results, graph_path = analyze_script(script)
112
+ dashboard_content = format_dashboard(analysis_results)
113
+ return dashboard_content, graph_path
114
+
115
+ display_dashboard_button.click(display_dashboard, inputs=script_input, outputs=[output_dashboard, output_graph])
116
+
117
+ # Launch the Gradio app with sharing enabled
118
+ interface.launch(share=True)
script_emotional_arc.png ADDED