Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import plotly.graph_objects as go | |
| from gradio.themes.base import Base | |
| from gradio.themes.utils import colors, fonts, sizes | |
| from typing import Iterable | |
| class CustomTheme(Base): | |
| def __init__( | |
| self, | |
| *, | |
| primary_hue: colors.Color | str = colors.green, | |
| secondary_hue: colors.Color | str = colors.purple, | |
| neutral_hue: colors.Color | str = colors.gray, | |
| spacing_size: sizes.Size | str = sizes.spacing_md, | |
| radius_size: sizes.Size | str = sizes.radius_md, | |
| text_size: sizes.Size | str = sizes.text_md, | |
| font: fonts.Font | str | Iterable[fonts.Font | str] = ( | |
| fonts.GoogleFont("Nunito"), | |
| "ui-sans-serif", | |
| "sans-serif", | |
| ), | |
| font_mono: fonts.Font | str | Iterable[fonts.Font | str] = ( | |
| fonts.GoogleFont("Nunito"), | |
| "ui-monospace", | |
| "monospace", | |
| ), | |
| ): | |
| super().__init__( | |
| primary_hue=primary_hue, | |
| secondary_hue=secondary_hue, | |
| neutral_hue=neutral_hue, | |
| spacing_size=spacing_size, | |
| radius_size=radius_size, | |
| text_size=text_size, | |
| font=font, | |
| font_mono=font_mono, | |
| ) | |
| super().set( | |
| body_background_fill="radial-gradient(#32CD32 2px, transparent 2px), radial-gradient(#8A2BE2 4px, transparent 4px)", | |
| body_text_color="#282828", | |
| block_background_fill="#ffffff", | |
| block_title_text_color="#32CD32", | |
| block_label_text_color="#32CD32", | |
| button_primary_background_fill="#32CD32", | |
| button_primary_text_color="#FFFFFF", | |
| ) | |
| custom_theme = CustomTheme() | |
| def analyze_video(file_path): | |
| # Dummy sentiment analysis result | |
| sentiments = { | |
| "Joy": 12, | |
| "Trust": 10, | |
| "Fear": 8, | |
| "Surprise": 5, | |
| "Sadness": 7, | |
| "Disgust": 4, | |
| "Anger": 6, | |
| "Anticipation": 9 | |
| } | |
| labels = list(sentiments.keys()) | |
| values = list(sentiments.values()) | |
| fig = go.Figure(data=go.Scatterpolar( | |
| r=values + [values[0]], | |
| theta=labels + [labels[0]], | |
| fill='toself' | |
| )) | |
| fig.update_layout( | |
| polar=dict( | |
| radialaxis=dict( | |
| visible=True, | |
| range=[0, max(values) + 2] | |
| )), | |
| showlegend=False | |
| ) | |
| return fig | |
| # Custom CSS for additional styling | |
| css = """ | |
| #video_upload { | |
| background-color: #ffffff; | |
| color: #282828; | |
| border: 2px solid #32CD32; | |
| border-radius: 10px; | |
| padding: 10px; | |
| margin: 10px 0; | |
| } | |
| #submit_button { | |
| background-color: #32CD32; | |
| color: #FFFFFF; | |
| border: 2px solid #FFFFFF; | |
| border-radius: 10px; | |
| padding: 10px; | |
| margin: 10px 0; | |
| } | |
| #submit_button:hover { | |
| background-color: #3BFF3B; | |
| color: #FFFFFF; | |
| border: 2px solid #FFFFFF; | |
| } | |
| label[for="video_upload"] { | |
| color: #32CD32 !important; | |
| } | |
| h1 { | |
| color: white; | |
| text-shadow: -1px -1px 0 #32CD32, 1px -1px 0 #32CD32, -1px 1px 0 #32CD32, 1px 1px 0 #32CD32; | |
| font-size: 3em !important; | |
| font-weight: bold; | |
| text-transform: uppercase; | |
| } | |
| h3 { | |
| color: #32CD32; | |
| } | |
| .centered-markdown { | |
| text-align: center; | |
| background-color: #ffffff; | |
| border: 2px solid #32CD32; | |
| border-radius: 10px; | |
| padding: 10px; | |
| } | |
| #zeitgeist-title { | |
| font-size: 3em !important; | |
| font-weight: bold; | |
| text-transform: uppercase; | |
| background: none !important; | |
| } | |
| """ | |
| with gr.Blocks(theme=custom_theme, css=css) as demo: | |
| with gr.Column(): | |
| #gr.Markdown("# Zeitgeist AI", elem_classes="centered-markdown", elem_id="zeitgeist-title") | |
| #gr.Markdown("### Discover the emotional impact of your videos.", elem_classes="centered-markdown") | |
| #gr.Markdown("**Upload your video file to get started.**", elem_classes="centered-markdown") | |
| with gr.Row(): | |
| video_upload = gr.File(label="Upload Video File", type="filepath", elem_id="video_upload") | |
| output = gr.Plot(label="Sentiment Analysis Results", elem_id="output_plot") | |
| submit_button = gr.Button("Analyze Video", elem_id="submit_button") | |
| submit_button.click(fn=analyze_video, inputs=video_upload, outputs=output) | |
| demo.launch() |