Spaces:
Runtime error
Runtime error
Commit ·
1bd43e6
1
Parent(s): f75fbfe
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,188 +1,3 @@
|
|
| 1 |
-
# import gradio as gr
|
| 2 |
-
# import requests
|
| 3 |
-
# import re
|
| 4 |
-
# import boto3
|
| 5 |
-
# import os
|
| 6 |
-
# import json
|
| 7 |
-
# from gradio.components import Textbox
|
| 8 |
-
# from openai import OpenAI
|
| 9 |
-
# from pathlib import Path
|
| 10 |
-
|
| 11 |
-
# api_key= os.getenv('OPENAI_API_KEY')
|
| 12 |
-
|
| 13 |
-
# client = OpenAI(api_key=api_key)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# # Set your API keys and configurations here
|
| 17 |
-
# aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID')
|
| 18 |
-
# aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY')
|
| 19 |
-
# aws_default_region = os.getenv('AWS_DEFAULT_REGION')
|
| 20 |
-
# aws_session_token = os.getenv('AWS_SESSION_TOKEN')
|
| 21 |
-
# creatmote_api_key = os.getenv('CREATOMATE_API_KEY')
|
| 22 |
-
# bucket_name = os.getenv('BUCKET_NAME')
|
| 23 |
-
# folder_name = os.getenv('FOLDER_NAME')
|
| 24 |
-
|
| 25 |
-
# # Your content creation prompt
|
| 26 |
-
# content_creation_prompt = """
|
| 27 |
-
# [You are a teacher and a video creator and you create animated educational videos based on SLOs(Student learning outcomes) for students who don't really have a nag for the conventional ways of learning. You make sure that your video lessons are very very interesting and at the same time they still have all the teaching material that you want to incorporate. You have to make sure that the teaching material is logically incorporated within the stories, scenarios, or small daily life examples so that I can make an animated video out of it.
|
| 28 |
-
|
| 29 |
-
# As a creative assistant you are the best creative person out there and you have more than 30 years of experience. As a learning assistant you are better than the best of the teachers out there, you always know how to teach the given topic in a super easy manner and break it down so that your target audience can easily learn it.
|
| 30 |
-
# As a learning assistant you have more than 30 years of experience. As a creative assistant you will make sure that you come up with good ideas for the script and that you will incorporate all the teaching material into the story in a logical and creative manner and as a learning assistant you will make sure that you come up with good learning material and you will also make sure that creative assistant incorporates them in the story without being wrong about them.
|
| 31 |
-
|
| 32 |
-
# Please remember that whatever you create together is more about demonstration and less about telling. Please remember this film writing rule all the times Show don’t tell. You will be given an SLO. And at this point you will have two options and you will have to choose one.
|
| 33 |
-
|
| 34 |
-
# You have two options either proceed with story based learning or proceed with a short explainer video style. Whatever option you choose please remember to make it relevant to the Pakistani audience. Whatever option you may choose you have to make sure that you incorporate all the teaching material in that video.
|
| 35 |
-
|
| 36 |
-
# If you proceed with story based learning the story will always start with a big idea on that SLO. In the story based learning, the creative assistant will generate a big story idea around the given SLO. ( What is the big idea?: well Big idea of any video lesson is that one scene around which the whole story revolves, for instance in the SLO “Understand centripetal acceleration”, the big idea is showing a scene with a daredevil doing a loop de loop and not falling inwards. Why is this a big idea? Because a kid will see the potential crisis, and when the daredevil successfully completes the stunt, they will understand the concept of centripetal acceleration. Well, it's all about creating that "aha" moment. When a kid sees the daredevil in action, they get how centripetal acceleration works.) You have to add scenarios, examples, diagrams, explanations, or any other better option that you might have to suggest. Make sure the big idea has an element of conflict to it. Which the main protagonist has to face. The big idea should also be very relevant to the target audience. You will keep in mind that you have to demonstrate more than you talk about it.
|
| 37 |
-
|
| 38 |
-
# Skip the above step if a short explainer video is chosen.
|
| 39 |
-
|
| 40 |
-
# The explainer video includes multiple examples, and short scenarios directly told to the target audience through a narrator. Short explainer videos can have very minimal visual design. Either way you will keep in mind that you have to demonstrate more than you talk about it. If the short explainer video is chosen then the topic does not need a story around it. In Fact Creative assistant will keep this video simple enough and will generate idea for it without adding a story. It will certainly have a narrative but no complete story. It is always encouraged to start by asking questions. You have to add scenarios, examples, diagrams, explanations, or any other better option that you might have to suggest. These scripts are relatively shorter and more concise and to the point. Important thing to notice is that this format is short, simple, crisp, to the point, and very very visual. short explainer videos can have very minimal visual design
|
| 41 |
-
|
| 42 |
-
# your output will be in a script format. Timestamps would be mentioned, write voiceovers and provide prompts for static visuals from the story. Prompts for visuals would always be labeled as VISUAL PROMPT. Mention Timestamps for each scene. PLEASE ALWAYS MENTION VOICE OVERS AS V.O AND PROMPTS FOR VISUALS AS VISUAL PROMPT. ALSO MENTION THE SCENE NUMBERS. You must give 10 visual prompts at all times. if the user gives you an SLO that is half or broken or does not make any sense, you must fix it and improve it and show it to the user that this is how you fixed it. you must always ask for the grade for which you have to keep the difficult level for. no magic themes in both formats what so ever
|
| 43 |
-
|
| 44 |
-
# "Generate a detailed prompt for a static animated image. The prompt should vividly describe a scene that includes the following elements:
|
| 45 |
-
|
| 46 |
-
# 1. **Setting**: Specify a unique and engaging environment, such as an enchanted forest, a futuristic city, an underwater kingdom, a space station, or a historical setting like a medieval marketplace.
|
| 47 |
-
|
| 48 |
-
# 2. **Key Features**: Include specific details about the landscape, architecture, and any notable features of the setting. For instance, glowing plants, futuristic buildings, coral palaces, spaceships, or market stalls.
|
| 49 |
-
|
| 50 |
-
# 3. **Atmosphere and Lighting**: Describe the time of day and the overall atmosphere, highlighting elements like lighting (bioluminescent, neon, sunlight filtering through water, etc.) and mood (mystical, bustling, serene, etc.).
|
| 51 |
-
|
| 52 |
-
# 4. **Characters and Lifeforms**: Mention any characters, creatures, or life forms present in the scene, whether they are people, animals, mythical beings, or aliens. Describe their appearance and activities.
|
| 53 |
-
|
| 54 |
-
# 5. **Additional Elements**: Add any extra details that will bring the scene to life, such as specific actions occurring, types of objects present, or interactions between characters.
|
| 55 |
-
|
| 56 |
-
# The prompt should be detailed and evoke a clear and vivid image of the scene, allowing for a diverse and imaginative interpretation when visualized.]
|
| 57 |
-
# """
|
| 58 |
-
|
| 59 |
-
# def generate_voiceover(line, index, bucket_name, folder_name):
|
| 60 |
-
# # Initialize the S3 client
|
| 61 |
-
# s3 = boto3.client('s3')
|
| 62 |
-
|
| 63 |
-
# # Generate a unique file name for each line
|
| 64 |
-
# file_name = f"vo_line_{index + 1}.mp3"
|
| 65 |
-
# speech_file_path = Path(file_name)
|
| 66 |
-
|
| 67 |
-
# # Generate voiceover using OpenAI
|
| 68 |
-
# response = client.audio.speech.create(
|
| 69 |
-
# model="tts-1",
|
| 70 |
-
# voice="alloy",
|
| 71 |
-
# input=line
|
| 72 |
-
# )
|
| 73 |
-
|
| 74 |
-
# # Write the audio content to a local file
|
| 75 |
-
# with open(speech_file_path, 'wb') as f:
|
| 76 |
-
# f.write(response.content)
|
| 77 |
-
|
| 78 |
-
# # Construct the S3 key (path in the bucket)
|
| 79 |
-
# s3_key = f"{folder_name}/{file_name}"
|
| 80 |
-
|
| 81 |
-
# # Upload the file to S3 inside the specified folder
|
| 82 |
-
# s3.upload_file(
|
| 83 |
-
# Filename=str(speech_file_path),
|
| 84 |
-
# Bucket=bucket_name,
|
| 85 |
-
# Key=s3_key
|
| 86 |
-
# )
|
| 87 |
-
|
| 88 |
-
# # Generate and return the S3 URL for the uploaded file
|
| 89 |
-
# return f'https://{bucket_name}.s3.amazonaws.com/{s3_key}'
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
# def generate_image(visual_prompt, API_KEY, ENDPOINT):
|
| 93 |
-
# # Create the Request Payload
|
| 94 |
-
# payload = {
|
| 95 |
-
# "model": "dall-e-3",
|
| 96 |
-
# "prompt": f"<{visual_prompt.strip()}>",
|
| 97 |
-
# "n": 1,
|
| 98 |
-
# "size": "1024x1024"
|
| 99 |
-
# }
|
| 100 |
-
|
| 101 |
-
# # Make the POST Request
|
| 102 |
-
# headers = {
|
| 103 |
-
# 'Authorization': f'Bearer {API_KEY}',
|
| 104 |
-
# 'Content-Type': 'application/json'
|
| 105 |
-
# }
|
| 106 |
-
|
| 107 |
-
# response = requests.post(ENDPOINT, json=payload, headers=headers)
|
| 108 |
-
|
| 109 |
-
# # Handle the Response
|
| 110 |
-
# if response.status_code == 200:
|
| 111 |
-
# image_url = response.json()['data'][0]['url']
|
| 112 |
-
# return image_url
|
| 113 |
-
# else:
|
| 114 |
-
# raise Exception(f"Error in image generation: {response.status_code}, {response.text}")
|
| 115 |
-
|
| 116 |
-
# def generate_video(slo):
|
| 117 |
-
# # Step 1: Script Generation
|
| 118 |
-
# render_url = 'https://api.creatomate.com/v1/renders'
|
| 119 |
-
# combined_prompt = f"{content_creation_prompt}\n\nBased on the following Student Learning Objective (SLO): '{slo}', generate a detailed script for an educational video."
|
| 120 |
-
# script_response = client.chat.completions.create(model="gpt-4", messages=[{"role": "user", "content": combined_prompt}])
|
| 121 |
-
# script_text = script_response.choices[0].message.content
|
| 122 |
-
# print (script_text)
|
| 123 |
-
|
| 124 |
-
# # Step 2: Image Generation
|
| 125 |
-
# pattern = r'^VISUAL PROMPT:(.*)$'
|
| 126 |
-
# visual_prompts = re.findall(pattern, script_text, re.MULTILINE)
|
| 127 |
-
# generated_image_urls = []
|
| 128 |
-
# API_KEY = api_key
|
| 129 |
-
# ENDPOINT = 'https://api.openai.com/v1/images/generations'
|
| 130 |
-
# for visual_prompt in visual_prompts:
|
| 131 |
-
# image_url = generate_image(visual_prompt, API_KEY, ENDPOINT)
|
| 132 |
-
# generated_image_urls.append(image_url)
|
| 133 |
-
|
| 134 |
-
# # Step 3: Voiceover Generation and Upload to AWS S3
|
| 135 |
-
# pattern_vo = r'^V\.O:\s*(.*?)$'
|
| 136 |
-
# vo_lines = re.findall(pattern_vo, script_text, re.MULTILINE)
|
| 137 |
-
# s3 = boto3.client('s3', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key,aws_session_token=aws_session_token, region_name=aws_default_region)
|
| 138 |
-
# s3_voiceover_urls = []
|
| 139 |
-
|
| 140 |
-
# for i, line in enumerate(vo_lines):
|
| 141 |
-
# s3_url = generate_voiceover(line, i, bucket_name, folder_name)
|
| 142 |
-
# s3_voiceover_urls.append(s3_url)
|
| 143 |
-
|
| 144 |
-
# # Step 4: Video Compilation with Creatomate
|
| 145 |
-
# modifications = {f'Visual prompt-{i+1}': url for i, url in enumerate(generated_image_urls)}
|
| 146 |
-
# for index, audio_url in enumerate(s3_voiceover_urls):
|
| 147 |
-
# modifications[f"vo_line_{index+1}"] = audio_url
|
| 148 |
-
# payload = {
|
| 149 |
-
# 'template_id': '6f315232-a8eb-4d1b-9079-1b9ee595cc2b',
|
| 150 |
-
# 'modifications': modifications,
|
| 151 |
-
# }
|
| 152 |
-
# headers = {
|
| 153 |
-
# 'Authorization': f'Bearer {creatmote_api_key}',
|
| 154 |
-
# 'Content-Type': 'application/json'
|
| 155 |
-
# }
|
| 156 |
-
# try:
|
| 157 |
-
# # Make the POST request to Creatomate
|
| 158 |
-
# response = requests.post(render_url, data=json.dumps(payload), headers=headers)
|
| 159 |
-
# response.raise_for_status() # This will raise an error for bad status codes
|
| 160 |
-
|
| 161 |
-
# # Debugging: Print the response JSON
|
| 162 |
-
# print("Response JSON:", response.json())
|
| 163 |
-
|
| 164 |
-
# # Extract video URL from the response
|
| 165 |
-
# response_data = response.json()
|
| 166 |
-
# if response_data and isinstance(response_data, list) and len(response_data) > 0:
|
| 167 |
-
# video_url = response_data[0].get('url', 'No URL found in the response')
|
| 168 |
-
# else:
|
| 169 |
-
# video_url = 'No valid data in response'
|
| 170 |
-
|
| 171 |
-
# return video_url
|
| 172 |
-
# except requests.RequestException as error:
|
| 173 |
-
# error_message = f"An error occurred: {str(error)}"
|
| 174 |
-
# print(error_message)
|
| 175 |
-
# # print("Response content:", response.text)
|
| 176 |
-
# return error_message
|
| 177 |
-
|
| 178 |
-
# # Gradio Interface
|
| 179 |
-
# iface = gr.Interface(
|
| 180 |
-
# fn=generate_video,
|
| 181 |
-
# inputs=gr.Textbox(label="Enter Student Learning Objective (SLO)"),
|
| 182 |
-
# outputs=gr.Textbox(label="Generated Video URL")
|
| 183 |
-
# )
|
| 184 |
-
|
| 185 |
-
# iface.queue().launch(share=True)
|
| 186 |
import gradio as gr
|
| 187 |
import requests
|
| 188 |
import re
|
|
@@ -193,19 +8,19 @@ from gradio.components import Textbox
|
|
| 193 |
from openai import OpenAI
|
| 194 |
from pathlib import Path
|
| 195 |
|
| 196 |
-
api_key= '
|
| 197 |
|
| 198 |
client = OpenAI(api_key=api_key)
|
| 199 |
|
| 200 |
|
| 201 |
# Set your API keys and configurations here
|
| 202 |
-
aws_access_key_id = '
|
| 203 |
-
aws_secret_access_key = '
|
| 204 |
-
aws_default_region = '
|
| 205 |
-
aws_session_token = '
|
| 206 |
-
creatmote_api_key = '
|
| 207 |
-
bucket_name = '
|
| 208 |
-
folder_name = '
|
| 209 |
|
| 210 |
# Your content creation prompt
|
| 211 |
content_creation_prompt = """
|
|
@@ -310,7 +125,7 @@ def generate_video(slo):
|
|
| 310 |
pattern = r'^VISUAL PROMPT:(.*)$'
|
| 311 |
visual_prompts = re.findall(pattern, script_text, re.MULTILINE)
|
| 312 |
generated_image_urls = []
|
| 313 |
-
API_KEY =
|
| 314 |
ENDPOINT = 'https://api.openai.com/v1/images/generations'
|
| 315 |
for visual_prompt in visual_prompts:
|
| 316 |
image_url = generate_image(visual_prompt, API_KEY, ENDPOINT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import re
|
|
|
|
| 8 |
from openai import OpenAI
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
+
api_key= os.getenv('OPENAI_API_KEY')
|
| 12 |
|
| 13 |
client = OpenAI(api_key=api_key)
|
| 14 |
|
| 15 |
|
| 16 |
# Set your API keys and configurations here
|
| 17 |
+
aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID')
|
| 18 |
+
aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY')
|
| 19 |
+
aws_default_region = os.getenv('AWS_DEFAULT_REGION')
|
| 20 |
+
aws_session_token = os.getenv('AWS_SESSION_TOKEN')
|
| 21 |
+
creatmote_api_key = os.getenv('CREATOMATE_API_KEY')
|
| 22 |
+
bucket_name = os.getenv('BUCKET_NAME')
|
| 23 |
+
folder_name = os.getenv('FOLDER_NAME')
|
| 24 |
|
| 25 |
# Your content creation prompt
|
| 26 |
content_creation_prompt = """
|
|
|
|
| 125 |
pattern = r'^VISUAL PROMPT:(.*)$'
|
| 126 |
visual_prompts = re.findall(pattern, script_text, re.MULTILINE)
|
| 127 |
generated_image_urls = []
|
| 128 |
+
API_KEY = api_key
|
| 129 |
ENDPOINT = 'https://api.openai.com/v1/images/generations'
|
| 130 |
for visual_prompt in visual_prompts:
|
| 131 |
image_url = generate_image(visual_prompt, API_KEY, ENDPOINT)
|