mediacrawler2 / app.py
seawolf2357's picture
Deploy from GitHub repository
842e08e verified
import gradio as gr
import httpx
# Function to simulate media data crawling
async def crawl_media(platform, keyword, api_key):
if not api_key:
return "Error: API key is required. Please provide a valid API key."
try:
# Simulate a media crawling process
response = await httpx.get(f'https://api.example.com/crawl?platform={platform}&keyword={keyword}', headers={'Authorization': f'Bearer {api_key}'})
if response.status_code == 200:
return response.json()
else:
return f"Error: Unable to crawl data. Status code: {response.status_code}"
except Exception as e:
return f"Error: {str(e)}"
# Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Media Crawler\nA powerful multi-platform media data collection tool.\n\n## Instructions\n1. Enter the platform you want to crawl (e.g., '小红书', '抖音').\n2. Provide a keyword for the search.\n3. Enter your API key to authenticate the request.\n\n### Example\n- Platform: '小红书'\n- Keyword: '旅行'\n").style(height=200)
platform = gr.Textbox(label="Platform", placeholder="Enter platform name")
keyword = gr.Textbox(label="Keyword", placeholder="Enter search keyword")
api_key = gr.Textbox(label="API Key", placeholder="Enter your API key")
output = gr.Textbox(label="Output")
submit_btn = gr.Button("Crawl Data")
submit_btn.click(crawl_media, inputs=[platform, keyword, api_key], outputs=output)
# Launch the app
if __name__ == "__main__":
demo.launch()