Spaces:
Sleeping
Sleeping
GPTによる要約部分を修正
Browse files- youtube_ana_gradio.py +7 -16
youtube_ana_gradio.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from googleapiclient.discovery import build
|
4 |
-
from googleapiclient.errors import HttpError
|
5 |
import plotly.express as px
|
6 |
import base64
|
7 |
import numpy as np
|
@@ -126,14 +125,14 @@ def analyze_titles(video_stats_df, openai_key, n_clusters=5):
|
|
126 |
|
127 |
def summarize_cluster(cluster_text, openai_key, cluster_num):
|
128 |
openai.api_key = openai_key
|
129 |
-
prompt = f"
|
130 |
response = openai.ChatCompletion.create(
|
131 |
model="gpt-3.5-turbo",
|
132 |
messages=[
|
133 |
{"role": "system", "content": "あなたは世界中の人気動画や大規模データを解析してきた天才AI・データサイエンティストです"},
|
134 |
{"role": "user", "content": prompt}
|
135 |
],
|
136 |
-
max_tokens=
|
137 |
n=1,
|
138 |
stop=None,
|
139 |
temperature=0.7,
|
@@ -163,13 +162,13 @@ def main(api_key, openai_key, query, max_results, period, page, n_clusters=5):
|
|
163 |
|
164 |
elif page == "Title Analysis":
|
165 |
cluster_summary_df = analyze_titles(video_stats_df, openai_key, n_clusters)
|
166 |
-
return cluster_summary_df
|
167 |
|
168 |
iface = gr.Interface(
|
169 |
fn=main,
|
170 |
inputs=[
|
171 |
-
gr.components.Textbox(label="YouTube API Key", type="password"),
|
172 |
-
gr.components.Textbox(label="OpenAI API Key", type="password"),
|
173 |
gr.components.Textbox(label="Search query"),
|
174 |
gr.components.Slider(minimum=1, maximum=1000, value=5, label="Max results"),
|
175 |
gr.components.Dropdown(["1週間", "1か月", "3か月"], label="Period"),
|
@@ -182,16 +181,8 @@ iface = gr.Interface(
|
|
182 |
gr.components.HTML(label="CSV Download Link")
|
183 |
],
|
184 |
live=False,
|
185 |
-
title="YouTube
|
186 |
-
description="YouTubeの動画を検索し、タイトル分析やランキングを行います。"
|
187 |
)
|
188 |
|
189 |
-
#def update_message(request: gr.Request):
|
190 |
-
# return f"Welcome, {request.username}"
|
191 |
-
|
192 |
-
# with gr.Blocks() as demo:
|
193 |
-
# m = gr.Markdown()
|
194 |
-
# iface.load(update_message, None, m)
|
195 |
-
|
196 |
if __name__ == "__main__":
|
197 |
-
iface.launch(
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from googleapiclient.discovery import build
|
|
|
4 |
import plotly.express as px
|
5 |
import base64
|
6 |
import numpy as np
|
|
|
125 |
|
126 |
def summarize_cluster(cluster_text, openai_key, cluster_num):
|
127 |
openai.api_key = openai_key
|
128 |
+
prompt = f"これらの動画を日本語で徹底解析して要約し、動画の特徴・人気要因を500文字以内で解説してください: {cluster_text}"
|
129 |
response = openai.ChatCompletion.create(
|
130 |
model="gpt-3.5-turbo",
|
131 |
messages=[
|
132 |
{"role": "system", "content": "あなたは世界中の人気動画や大規模データを解析してきた天才AI・データサイエンティストです"},
|
133 |
{"role": "user", "content": prompt}
|
134 |
],
|
135 |
+
max_tokens=500,
|
136 |
n=1,
|
137 |
stop=None,
|
138 |
temperature=0.7,
|
|
|
162 |
|
163 |
elif page == "Title Analysis":
|
164 |
cluster_summary_df = analyze_titles(video_stats_df, openai_key, n_clusters)
|
165 |
+
return cluster_summary_df, None, None
|
166 |
|
167 |
iface = gr.Interface(
|
168 |
fn=main,
|
169 |
inputs=[
|
170 |
+
gr.components.Textbox(label="YouTube API Keyを入力してください", type="password"),
|
171 |
+
gr.components.Textbox(label="OpenAI API Keyを入力してください", type="password"),
|
172 |
gr.components.Textbox(label="Search query"),
|
173 |
gr.components.Slider(minimum=1, maximum=1000, value=5, label="Max results"),
|
174 |
gr.components.Dropdown(["1週間", "1か月", "3か月"], label="Period"),
|
|
|
181 |
gr.components.HTML(label="CSV Download Link")
|
182 |
],
|
183 |
live=False,
|
184 |
+
title="YouTube Analysis Tool"
|
|
|
185 |
)
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
if __name__ == "__main__":
|
188 |
+
iface.launch()
|