JKin commited on
Commit
fdfe9b6
·
verified ·
1 Parent(s): 71b8046

Update app.py

Browse files

Adding in the basic interface structure

Files changed (1) hide show
  1. app.py +97 -83
app.py CHANGED
@@ -1,107 +1,121 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import numpy as np
4
- import gradio as gr
5
  import random
6
 
7
- def flip_text(x):
8
- return x[::-1]
9
-
10
- def flip_image(x):
11
- return np.fliplr(x)
12
-
13
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  df = pd.DataFrame({
15
  'Year': np.random.randint(2000, 2024, 25),
16
  'Reviews': np.random.randint(120, 320, 25),
17
- 'age': np.random.randint(18, 30, 25),
18
- 'ethnicity': [random.choice(["white", "black", "asian"]) for _ in range(25)]
19
  })
20
 
 
21
  theme = gr.themes.Soft(
22
  primary_hue="yellow",
23
  secondary_hue="amber",
24
  spacing_size="sm",
25
  radius_size="lg",
26
-
27
  )
28
 
29
  with gr.Blocks(theme=theme) as demo:
30
 
31
- gr.ScatterPlot(df, x="Reviews", y="age", color="age")
32
- gr.LinePlot(df, x="Year", y="Reviews")
33
- gr.Slider(2000, 2024, value=2024, label="Count", info="Choose between 2000 and 2024"),
34
- gr.Markdown("Flip text or image files using this demo.")
35
  with gr.Tab("User Interface"):
36
- text_input = gr.Textbox()
37
- text_output = gr.Textbox()
38
- text_button = gr.Button("Flip")
39
- with gr.Tab("Testing Area"):
40
- with gr.Row():
41
- image_input = gr.Image()
42
- image_output = gr.Image()
43
- image_button = gr.Button("Flip")
44
- with gr.Row("Flip Text"):
45
- text_input = gr.Textbox()
46
- text_output = gr.Textbox()
47
- text_button = gr.Button("Flip")
48
- with gr.Column(visible=False) as output_col:
49
- text_input = gr.Textbox()
50
- text_output = gr.Textbox()
51
- text_button = gr.Button("Flip")
52
-
53
-
54
- with gr.Accordion("Open for More!", open=False):
55
- gr.Markdown("Look at me...")
56
- temp_slider = gr.Slider(
57
- 0, 1,
58
- value=0.1,
59
- step=0.1,
60
- interactive=True,
61
- label="Slide me",
62
- )
63
-
64
- text_button.click(flip_text, inputs=text_input, outputs=text_output)
65
- image_button.click(flip_image, inputs=image_input, outputs=image_output)
66
-
67
- track_count = gr.State(1)
68
- add_track_btn = gr.Button("Add Track")
69
-
70
- add_track_btn.click(lambda count: count + 1, track_count, track_count)
71
-
72
- @gr.render(inputs=track_count)
73
- def render_tracks(count):
74
- audios = []
75
- volumes = []
76
- with gr.Row():
77
- for i in range(count):
78
- with gr.Column(variant="panel", min_width=200):
79
- gr.Textbox(placeholder="Data Name", key=f"name-{i}", show_label=False)
80
- track_audio = gr.Audio(label=f"Data {i}", key=f"track-{i}")
81
- track_volume = gr.Slider(0, 100, value=100, label="Volume", key=f"volume-{i}")
82
- audios.append(track_audio)
83
- volumes.append(track_volume)
84
-
85
- def merge(data):
86
- sr, output = None, None
87
- for audio, volume in zip(audios, volumes):
88
- sr, audio_val = data[audio]
89
- volume_val = data[volume]
90
- final_track = audio_val * (volume_val / 100)
91
- if output is None:
92
- output = final_track
93
- else:
94
- min_shape = tuple(min(s1, s2) for s1, s2 in zip(output.shape, final_track.shape))
95
- trimmed_output = output[:min_shape[0], ...][:, :min_shape[1], ...] if output.ndim > 1 else output[:min_shape[0]]
96
- trimmed_final = final_track[:min_shape[0], ...][:, :min_shape[1], ...] if final_track.ndim > 1 else final_track[:min_shape[0]]
97
- output += trimmed_output + trimmed_final
98
- return (sr, output)
99
-
100
- merge_btn.click(merge, set(audios + volumes), output_audio)
101
-
102
- merge_btn = gr.Button("Merge Tracks")
103
- output_audio = gr.Audio(label="Output", interactive=False)
104
 
 
 
105
 
 
 
 
 
106
 
107
  demo.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
  import numpy as np
 
4
  import random
5
 
6
+ def show_stars():
7
+ """ Function that shows the HTML script for stars -Janika"""
8
+ stars_html = """
9
+ <style>
10
+ /* Title */
11
+ .title-text {
12
+ color: white;
13
+ font-family: sans-serif;
14
+ font-size: 1rem;
15
+ font-weight: bold;
16
+ }
17
+
18
+ /* Empty stars */
19
+ .star-rating {
20
+ display: inline-block;
21
+ font-size: 2em;
22
+ color: lightgray;
23
+ }
24
+
25
+ /* Filled stars */
26
+ .star-rating .star.filled {
27
+ color: gold;
28
+ }
29
+
30
+ /* Box for the whole star rating component */
31
+ .rating-box {
32
+ border: 1px transparent;
33
+ background-color: #1f2937;
34
+ padding: 10px;
35
+ border-radius: 5px;
36
+ width: fit-content;
37
+ margin-left: 0;
38
+ }
39
+
40
+ /* Box for the title */
41
+ .title-box {
42
+ border: 1px transparent;
43
+ background-color: #ca8a04;
44
+ padding: 3px;
45
+ border-radius: 5px;
46
+ display: inline-block;
47
+ margin-bottom: 6px;
48
+ }
49
+
50
+ /* Box for stars */
51
+ .star-box {
52
+ border: 1px transparent;
53
+ background-color: #374151;
54
+ padding: 10px;
55
+ border-radius: 5px;
56
+ width: fit-content;
57
+ margin: 0;
58
+ }
59
+ </style>
60
+
61
+ <div class="rating-box">
62
+ <div class="title-box">
63
+ <p class="title-text">Star rating</p>
64
+ </div>
65
+ <div class="star-box">
66
+ <div class="star-rating" data-rating="4">
67
+ <span class="star">★</span>
68
+ <span class="star">★</span>
69
+ <span class="star">★</span>
70
+ <span class="star">★</span>
71
+ <span class="star">★</span>
72
+ </div>
73
+ </div>
74
+ </div>
75
+
76
+ <script>
77
+ document.addEventListener('DOMContentLoaded', function() {
78
+ const ratingElement = document.querySelector('.star-rating');
79
+ const rating = parseInt(ratingElement.getAttribute('data-rating'));
80
+ const stars = ratingElement.querySelectorAll('.star');
81
+ for (let i = 0; i < rating; i++) {
82
+ stars[i].classList.add('filled');
83
+ }
84
+ });
85
+ </script>
86
+ """
87
+ return stars_html
88
+
89
+ # Random data for testing, actual data added later
90
  df = pd.DataFrame({
91
  'Year': np.random.randint(2000, 2024, 25),
92
  'Reviews': np.random.randint(120, 320, 25),
 
 
93
  })
94
 
95
+ # Theme
96
  theme = gr.themes.Soft(
97
  primary_hue="yellow",
98
  secondary_hue="amber",
99
  spacing_size="sm",
100
  radius_size="lg",
 
101
  )
102
 
103
  with gr.Blocks(theme=theme) as demo:
104
 
105
+ # Basic user interface for company's view -Janika
 
 
 
106
  with gr.Tab("User Interface"):
107
+ # Summary
108
+ summary_output = gr.Textbox(label="Summary")
109
+
110
+ # Star rating
111
+ star_rating = gr.HTML(value=show_stars())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
+ # Keywords
114
+ keywords_output = gr.Textbox(label="Keywords")
115
 
116
+ # Testing Area, for Piitu -Janika
117
+ with gr.Tab("Testing Area"):
118
+ with gr.Row():
119
+ text_input = gr.Textbox()
120
 
121
  demo.launch()