Skip to content

Commit cf95f38

Browse files
authored
Merge pull request #255 from shubhagarwal1/pages
ADD Review Submission Page and API Documentation Page
2 parents 424c551 + f4695ca commit cf95f38

File tree

3 files changed

+320
-0
lines changed

3 files changed

+320
-0
lines changed

Web_app/movie_reviews.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Name,Movie,Review
2+

Web_app/pages/API_Documentation.py

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import streamlit as st
2+
3+
st.subheader(" API Documentation", divider="rainbow")
4+
# Custom CSS for styling
5+
st.markdown(
6+
"""
7+
<style>
8+
body {
9+
color: #333;
10+
font-family: 'Arial', sans-serif;
11+
}
12+
.faq-title {
13+
color: #FF5733;
14+
font-size: 24px;
15+
margin-top: 20px;
16+
font-weight: bold;
17+
}
18+
.code-snippet {
19+
font-family: 'Courier New', monospace;
20+
background-color: #f0f0f0;
21+
padding: 10px;
22+
border-radius: 5px;
23+
color: black;
24+
}
25+
</style>
26+
""",
27+
unsafe_allow_html=True,
28+
)
29+
30+
# API Product Overview
31+
st.subheader("🔍 API Product Overview")
32+
st.write(
33+
"The IMDb API on AWS Data Exchange offers a GraphQL-based approach, enabling efficient data access for movie and TV series metadata, "
34+
"ratings, and box office data in real-time. It provides a streamlined JSON structure and single URL access for reduced API calls."
35+
)
36+
37+
# Benefits
38+
st.subheader("🌟 Key Benefits")
39+
st.markdown(
40+
"""
41+
- **One Call, All Data**: Access all data via a single URL.
42+
- **Flexible Queries**: Request only the specific fields you need, minimizing data over-fetching.
43+
- **Real-time Updates**: Receive IMDb’s latest data without delay.
44+
- **Multiple Entities**: Query multiple titles/names simultaneously.
45+
""",
46+
unsafe_allow_html=True,
47+
)
48+
49+
# Getting Access to the API
50+
st.subheader("🔑 Getting Access to the API")
51+
st.write(
52+
"To access the IMDb API, you need an AWS account and AWS Access Keys. Follow these steps to set up your access."
53+
)
54+
st.markdown(
55+
"""
56+
1. **Create an AWS Account**: The IMDb API is available through AWS Data Exchange.
57+
2. **Obtain AWS Access Keys**: Generate your keys for API authentication.
58+
3. **Enable Cost Explorer (Optional)**: View your usage and cost in AWS Cost Explorer.
59+
""",
60+
unsafe_allow_html=True,
61+
)
62+
63+
# Authentication and API Key
64+
st.subheader("🔒 Authentication and API Key")
65+
st.write(
66+
"For API calls, the `x-api-key` header must include your API Key. Authenticate requests using AWS credentials in one of the following ways."
67+
)
68+
69+
# Code Snippet for AWS CLI
70+
st.markdown(
71+
"""
72+
**Example API Call (AWS CLI)**:
73+
""",
74+
unsafe_allow_html=True,
75+
)
76+
st.code(
77+
"""
78+
aws dataexchange send-api-asset \\
79+
--data-set-id <Dataset ID> \\
80+
--revision-id <Revision ID> \\
81+
--asset-id <Asset ID> \\
82+
--request-headers "{ 'x-api-key': '<Your API Key>'}" \\
83+
--region us-east-1 \\
84+
--body "{ 'query': '{ title(id: \"tt0120338\") { ratingsSummary { aggregateRating voteCount } } }' }"
85+
""",
86+
language="bash",
87+
)
88+
89+
# Sample GraphQL Query
90+
st.subheader("💻 Sample Query")
91+
st.write("Here’s a sample GraphQL query to retrieve the IMDb rating for *Titanic*:")
92+
93+
st.markdown(
94+
"""
95+
<div class="code-snippet">
96+
{
97+
title(id: "tt0120338") {
98+
ratingsSummary {
99+
aggregateRating
100+
voteCount
101+
}
102+
}
103+
}
104+
</div>
105+
""",
106+
unsafe_allow_html=True,
107+
)
108+
109+
# Response Example
110+
st.subheader("📊 Sample API Response")
111+
st.write('{\n "data": {\n "title": {\n "ratingsSummary": {')
112+
st.write(' "aggregateRating": 7.9,\n "voteCount": 1133828')
113+
st.write(" }\n }\n }\n}")
114+
115+
# Additional Code Snippets
116+
st.subheader("📜 Additional Code Snippets")
117+
118+
# Code Snippet for Postman Request
119+
st.write("**Making Requests via Postman**")
120+
st.markdown(
121+
"""
122+
1. **Set Method**: Use `POST` method.
123+
2. **Request URL**: `https://api-fulfill.dataexchange.us-east-1.amazonaws.com/v1`
124+
3. **Headers**:
125+
- `Content-Type`: `application/json`
126+
- `x-api-key`: `<Your API Key>`
127+
4. **Body (GraphQL Query)**:
128+
```graphql
129+
{
130+
title(id: "tt0120338") {
131+
ratingsSummary {
132+
aggregateRating
133+
voteCount
134+
}
135+
}
136+
}
137+
```
138+
""",
139+
unsafe_allow_html=True,
140+
)
141+
142+
# Code Snippet for Python API Call
143+
st.write("**Python Code to Make an API Call**")
144+
st.code(
145+
"""
146+
import requests
147+
148+
url = "https://api-fulfill.dataexchange.us-east-1.amazonaws.com/v1"
149+
headers = {
150+
"x-api-key": "<Your API Key>",
151+
"Content-Type": "application/json"
152+
}
153+
query = '''
154+
{
155+
title(id: "tt0120338") {
156+
ratingsSummary {
157+
aggregateRating
158+
voteCount
159+
}
160+
}
161+
}
162+
'''
163+
response = requests.post(url, headers=headers, data=query)
164+
print(response.json())
165+
""",
166+
language="python",
167+
)
168+
169+
# Example Use Cases
170+
st.subheader("📄 Example Use Cases")
171+
st.markdown(
172+
"""
173+
1. **Retrieve Ratings**: Query title ratings and vote counts.
174+
2. **Box Office Data**: Access box office gross data.
175+
3. **Cast and Crew**: Fetch top cast or crew details for movies and shows.
176+
4. **Search Functionality**: Use keywords to find specific titles or names.
177+
5. **Real-time Data Access**: Display data updates as they become available on IMDb.
178+
""",
179+
unsafe_allow_html=True,
180+
)
181+
182+
# Footer
183+
st.markdown("---")
184+
st.markdown(
185+
"<small>For further assistance, contact support at [email protected]</small>",
186+
unsafe_allow_html=True,
187+
)

Web_app/pages/ReviewSubmission.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import streamlit as st
2+
import os
3+
import pandas as pd
4+
5+
# Set the path for storing the reviews
6+
reviews_file = "movie_reviews.csv"
7+
8+
# Initialize the reviews file if it doesn't exist
9+
if not os.path.exists(reviews_file):
10+
df = pd.DataFrame(columns=["Name", "Movie", "Review"])
11+
df.to_csv(reviews_file, index=False)
12+
13+
# Read the existing reviews from the file
14+
df = pd.read_csv(reviews_file)
15+
16+
# Initialize session state for showing the review form
17+
if "show_review_form" not in st.session_state:
18+
st.session_state.show_review_form = False
19+
20+
st.title("🎬 Submit Your Movie Review")
21+
22+
st.markdown(
23+
"<div style='height: 5px; background: linear-gradient(to right, #FF5733, #FFC300, #DAF7A6, #33FF57, #3380FF);'></div>",
24+
unsafe_allow_html=True,
25+
)
26+
27+
# Updated Custom CSS for Reddit-style reviews with dynamic sizing
28+
st.markdown(
29+
"""
30+
<style>
31+
.review-box {
32+
background-color: #f8f9fa;
33+
padding: 12px;
34+
border-radius: 4px;
35+
margin-bottom: 16px;
36+
border: 1px solid #e3e6e8;
37+
width: auto;
38+
max-width: 100%;
39+
height: auto;
40+
overflow-wrap: break-word;
41+
word-wrap: break-word;
42+
hyphens: auto;
43+
}
44+
.review-header {
45+
color: #1a1a1b;
46+
font-size: 12px;
47+
font-weight: 400;
48+
line-height: 16px;
49+
display: flex;
50+
align-items: center;
51+
margin-bottom: 8px;
52+
flex-wrap: wrap;
53+
}
54+
.review-author {
55+
color: #1c1c1c;
56+
font-weight: 700; /* Changed to bold */
57+
margin-right: 4px;
58+
text-transform: capitalize;
59+
}
60+
.review-movie {
61+
color: red;
62+
text-transform: capitalize;
63+
}
64+
.review-content {
65+
font-size: 14px;
66+
line-height: 21px;
67+
font-weight: 400;
68+
color: #1a1a1b;
69+
white-space: pre-wrap; /* Preserves line breaks and spaces */
70+
}
71+
.toggle-button {
72+
cursor: pointer;
73+
color: #0079D3;
74+
}
75+
</style>
76+
""",
77+
unsafe_allow_html=True,
78+
)
79+
80+
# Toggle for review form visibility
81+
show_review_form = st.checkbox(
82+
"➕ Submit Review", value=st.session_state.show_review_form, key="review_checkbox"
83+
)
84+
85+
# Update session state based on checkbox
86+
st.session_state.show_review_form = show_review_form
87+
88+
# Form for submitting reviews
89+
if st.session_state.show_review_form:
90+
with st.form(key="review_form"):
91+
name = st.text_input("Your Name")
92+
movie_name = st.text_input("Movie Name")
93+
review = st.text_area("Your Review", height=80)
94+
submit_button = st.form_submit_button(label="Submit Review")
95+
96+
if submit_button:
97+
if name and movie_name and review:
98+
new_review = pd.DataFrame(
99+
{
100+
"Name": [name],
101+
"Movie": [movie_name],
102+
"Review": [review],
103+
}
104+
)
105+
df = pd.concat([df, new_review], ignore_index=True)
106+
df.to_csv(reviews_file, index=False)
107+
st.success("Thank you for your review!")
108+
st.session_state.show_review_form = False
109+
st.rerun()
110+
else:
111+
st.error("Please fill in all fields before submitting.")
112+
113+
# Display the reviews in a Reddit-style comment format
114+
st.subheader("📜 Reviews")
115+
116+
if not df.empty:
117+
for index, row in df.iterrows():
118+
st.markdown(
119+
f"""
120+
<div class="review-box">
121+
<div class="review-header">
122+
<span class="review-author">{row['Name']}</span>
123+
<span class="review-movie">{row['Movie']}</span>
124+
</div>
125+
<div class="review-content">{row['Review']}</div>
126+
</div>
127+
""",
128+
unsafe_allow_html=True,
129+
)
130+
else:
131+
st.write("No reviews yet. Be the first to leave one!")

0 commit comments

Comments
 (0)