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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: 14px;
|
| 15 |
+
font-weight: bold;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/* Empty stars */
|
| 19 |
+
.star-rating {
|
| 20 |
+
display: inline-block;
|
| 21 |
+
font-size: 1.5em;
|
| 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: 100%;
|
| 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: 8px;
|
| 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 |
+
# Function to handle feedback submission -Piitu
|
| 96 |
+
def handle_feedback(feedback, name):
|
| 97 |
+
return f"Thank you for your feedback, {name}!"
|
| 98 |
+
|
| 99 |
+
# Function to update placeholder text -Piitu
|
| 100 |
+
def update_placeholder(name):
|
| 101 |
+
if name:
|
| 102 |
+
return f"Enter your feedback here, {name}..."
|
| 103 |
+
else:
|
| 104 |
+
return "Enter your feedback here..."
|
| 105 |
+
|
| 106 |
+
# Theme
|
| 107 |
+
theme = gr.themes.Soft(
|
| 108 |
+
primary_hue="yellow",
|
| 109 |
+
secondary_hue="amber",
|
| 110 |
+
spacing_size="sm",
|
| 111 |
+
radius_size="lg",
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
with gr.Blocks(theme=theme) as demo:
|
| 115 |
+
|
| 116 |
+
# Basic user interface for company's view -Janika
|
| 117 |
+
with gr.Tab("User Interface"):
|
| 118 |
+
with gr.Row():
|
| 119 |
+
with gr.Column(scale=1, min_width=300):
|
| 120 |
+
# Summary
|
| 121 |
+
summary_output = gr.Textbox(label="Summary")
|
| 122 |
+
|
| 123 |
+
with gr.Column(scale=2, min_width=300):
|
| 124 |
+
# Star rating
|
| 125 |
+
star_rating = gr.HTML(value=show_stars())
|
| 126 |
+
|
| 127 |
+
# Keywords
|
| 128 |
+
keywords_output = gr.Textbox(label="Keywords")
|
| 129 |
+
|
| 130 |
+
# Testing Area -Piitu
|
| 131 |
+
with gr.Tab("Testing Area"):
|
| 132 |
+
with gr.Row():
|
| 133 |
+
name_input = gr.Textbox(label="Enter your name", placeholder="Enter your name here...")
|
| 134 |
+
|
| 135 |
+
with gr.Row():
|
| 136 |
+
text_input = gr.Textbox(label="Please give us feedback!",
|
| 137 |
+
placeholder="Enter your feedback here...",
|
| 138 |
+
max_length=5000)
|
| 139 |
+
|
| 140 |
+
# Update placeholder based on name input -Piitu
|
| 141 |
+
name_input.change(fn=update_placeholder, inputs=name_input, outputs=text_input)
|
| 142 |
+
|
| 143 |
+
# Send button -Piitu
|
| 144 |
+
send_button = gr.Button("Send")
|
| 145 |
+
|
| 146 |
+
# Output for feedback submission confirmation -Piitu
|
| 147 |
+
feedback_output = gr.Textbox(label="Submission Result", interactive=False)
|
| 148 |
+
|
| 149 |
+
# Link button to function that handles feedback submission -Piitu
|
| 150 |
+
send_button.click(handle_feedback, inputs=[text_input, name_input], outputs=feedback_output)
|
| 151 |
+
|
| 152 |
+
demo.launch()
|