Team Ai
Apppublic

nniehaus/Local-Event-Video-Script-Generator

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py43 linesDownload Raw Back to root
1import requests2import gradio3 4def search_bing(query, api_key):5    search_url = "https://api.bing.microsoft.com/v7.0/search"6    headers = {"Ocp-Apim-Subscription-Key": api_key}7    params = {"q": query, "count": 10, "offset": 0, "mkt": "en-us", "safesearch": "Moderate"}8    response = requests.get(search_url, headers=headers, params=params)9    response.raise_for_status()10    return response.json()11 12def parse_events(response):13    events = []14    for value in response.get('webPages', {}).get('value', []):15        event_info = {'name': value.get('name'), 'url': value.get('url'), 'snippet': value.get('snippet')}16        events.append(event_info)17    return events18 19def get_events(city, audience):20    api_key = '7270575a6b9b4ac6ab6f5c5ae5a5b2db'21    query = f"upcoming {audience} events in {city}"22    response = search_bing(query, api_key)23    events = parse_events(response)24    events_list = [f"{event['name']} - {event['url']}" for event in events]25    return '\n'.join(events_list)26 27def main(city, audience):28    events_list = get_events(city, audience)29    return events_list30 31iface = gradio.Interface(32    fn=main,33    inputs=[34        gradio.components.Textbox(label="City", placeholder="Enter the city you're in"),35        gradio.components.Textbox(label="Audience", placeholder="Enter the target audience"),36    ],37    outputs=gradio.components.Textbox(),38    title="Upcoming Events Finder",39    description="Find upcoming events in your city for your target audience using Bing API.",40)41 42iface.launch()43