conhllnd commited on
Commit
7740bd4
·
verified ·
1 Parent(s): 34afe01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -2,8 +2,7 @@ import gradio as gr
2
  import pandas as pd
3
  from huggingface_hub import hf_hub_download
4
  import os
5
- import plotly.graph_objects as go # Import Plotly for graph plotting
6
-
7
 
8
  # Hugging Face API token and repo setup
9
  hf_token = os.getenv("hfkeymeow") # Ensure your token is correctly stored
@@ -106,6 +105,28 @@ def highlight_masterpiece_quintile(fig, actual_outcome, x_max):
106
  )
107
  return fig
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  # Create the Gradio interface
110
  with gr.Blocks() as dashboard:
111
 
@@ -142,7 +163,7 @@ with gr.Blocks() as dashboard:
142
  # Section for TikTok projections (Videos)
143
  with gr.Row():
144
  with gr.Column():
145
- video_path_1, graph_1 = load_data_and_plot("video", "TikTok1", download_file_from_repo("tiktok_histogram.csv"), download_file_from_repo("video_folder"))
146
  if video_path_1:
147
  gr.Video(video_path_1, label="TikTok 1 Video")
148
  gr.Plot(graph_1, label="TikTok 1 Performance")
@@ -181,3 +202,4 @@ with gr.Blocks() as dashboard:
181
 
182
  # Launch the dashboard
183
  dashboard.launch(debug=True)
 
 
2
  import pandas as pd
3
  from huggingface_hub import hf_hub_download
4
  import os
5
+ import plotly.graph_objects as go
 
6
 
7
  # Hugging Face API token and repo setup
8
  hf_token = os.getenv("hfkeymeow") # Ensure your token is correctly stored
 
105
  )
106
  return fig
107
 
108
+ # Function to load and plot data (TikTok, Facebook)
109
+ def load_data_and_plot(media_type, media_identifier, csv_path, folder_path):
110
+ df = pd.read_csv(csv_path)
111
+
112
+ # Assuming the CSV has columns 'Engagement' and 'Density'
113
+ x_data = df['Engagement']
114
+ y_data = df['Density']
115
+
116
+ # Create the plot with actual data
117
+ fig = go.Figure()
118
+ fig.add_trace(go.Scatter(x=x_data, y=y_data, mode='lines', name="Actual Data"))
119
+
120
+ # Adjust the x-axis and y-axis
121
+ fig.update_layout(
122
+ title=f"Predicted Engagement for {media_identifier}",
123
+ xaxis=dict(range=[0, max(x_data)]),
124
+ yaxis=dict(range=[0, max(y_data)])
125
+ )
126
+
127
+ media_file_path = None # Assuming you aren't showing media in this function
128
+ return media_file_path, fig
129
+
130
  # Create the Gradio interface
131
  with gr.Blocks() as dashboard:
132
 
 
163
  # Section for TikTok projections (Videos)
164
  with gr.Row():
165
  with gr.Column():
166
+ video_path_1, graph_1 = load_data_and_plot("video", "TikTok1", download_file_file_from_repo("tiktok_histogram.csv"), download_file_from_repo("video_folder"))
167
  if video_path_1:
168
  gr.Video(video_path_1, label="TikTok 1 Video")
169
  gr.Plot(graph_1, label="TikTok 1 Performance")
 
202
 
203
  # Launch the dashboard
204
  dashboard.launch(debug=True)
205
+