CoolFace
Apppublic

Abu1998/script_writing

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
script_writing.py84 linesDownload Raw Back to root
1import csv2import re3from datetime import datetime4from gradio_client import Client5import requests6import os7 8# Giphy API details9API_KEY = "KzPlVn6nz6czmjWpPEy6reL52r1H5gs7"10SEARCH_URL = "https://api.giphy.com/v1/gifs/search"11 12# Initialize the client with the correct Hugging Face Space13client = Client("Abu1998/Meme_finder")14print(client)  # Add this line to verify the client object15def generate_script(user_input):16    # Define the system message and input sentence17    18    print("Generating script for:", user_input)  # Add this line to verify the function call19    # ... rest of the function ...20    system_message = """Task: Act as a YouTube Shorts content writer.21 22Objective: Create engaging, catchy, and trendy scripts for YouTube Shorts videos that are brief, attention-grabbing, and optimized for viral potential.23 24Guidelines:25 26Each script should be 15-30 seconds long.27Use a hook in the first few seconds to capture viewers' attention.28Ensure the content is aligned with trending topics, challenges, or popular culture.29Incorporate humor, relatable scenarios, or strong emotions to resonate with the audience.30End with a clear call-to-action (CTA) like “Follow for more!” or a cliffhanger.31Example Flow:32 33User Input: “Write a script about the Monday blues.”34AI Output:35Script: "POV: It’s Monday morning, and you’re already done with the week. [Clip shows someone groggily hitting the snooze button, dragging themselves out of bed]. But wait… there’s coffee. And suddenly, everything’s okay! ☕✨ [Cut to a quick burst of energy with upbeat music]. If you’re just surviving till the weekend, hit that follow button for more relatable vibes!"36"""37 38    # Make the API call with the specified parameters39    result = client.predict(40        message=user_input,41        system_message=system_message,42        max_tokens=512,43        temperature=0.7,44        top_p=0.95,45        api_name="/chat"46    )47 48    # Extract the script from the result49    script = result.strip()50 51    # Function to split script into words52    def split_into_words(script_text):53        words = re.findall(r'\w+', script_text)  # Find all words54        return words55 56    # Convert the script to a list of words57    words = split_into_words(script)58 59    # Create download directory if it doesn't exist60    DOWNLOAD_DIR = '/content/memes2'61    os.makedirs(DOWNLOAD_DIR, exist_ok=True)62 63    # Download GIFs for each word64    for index, word in enumerate(words):65        params = {66            'api_key': API_KEY,67            'q': word,68            'limit': 169        }70        response = requests.get(SEARCH_URL, params=params)71        data = response.json()72 73        if data['data']:74            gif_url = data['data'][0]['images']['original']['url']75            gif_response = requests.get(gif_url)76 77            filename = f"{index}.gif"78            filepath = os.path.join(DOWNLOAD_DIR, filename)79 80            with open(filepath, 'wb') as f:81                f.write(gif_response.content)82            print(f"Downloaded GIF for '{word}' as '{filename}'")83 84    return script