soiz commited on
Commit
3141bb9
·
verified ·
1 Parent(s): 1a2b96c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+ import gradio as gr
4
+
5
+ def search_google_videos(query):
6
+ # 検索クエリをエンコードしてGoogleのURLを作成
7
+ url = f'https://www.google.com/search?q={query}&tbm=vid'
8
+
9
+ # GoogleにGETリクエストを送信
10
+ headers = {
11
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
12
+ }
13
+ response = requests.get(url, headers=headers)
14
+
15
+ # レスポンスを解析
16
+ soup = BeautifulSoup(response.text, 'html.parser')
17
+
18
+ # 動画の検索結果を取得
19
+ results = []
20
+ for result in soup.find_all('div', class_='BVG0Nb'):
21
+ title = result.find('h3').text
22
+ link = result.find('a')['href']
23
+ results.append(f"Title: {title}\nLink: {link}")
24
+
25
+ return "\n\n".join(results)
26
+
27
+ # Gradio インターフェースを作成
28
+ iface = gr.Interface(
29
+ fn=search_google_videos, # 実行する関数
30
+ inputs="text", # テキスト入力を使用
31
+ outputs="text", # テキスト出力を使用
32
+ title="Google Video Search", # タイトル
33
+ description="Enter a query to search videos on Google." # 説明
34
+ )
35
+
36
+ # Gradio アプリを起動
37
+ iface.launch()