Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
import requests | |
import os | |
import time | |
asr = pipeline("automatic-speech-recognition", model="openai/whisper-base.en") | |
def download_screenplay(screenplay): | |
filename = "generated_screenplay.txt" | |
with open(filename, "w", encoding="utf-8") as file: | |
file.write(screenplay) | |
display(HTML(f'<a href="{filename}" download>Download Screenplay</a>')) | |
def speech_to_text(speech): | |
text = asr(speech)["text"] | |
return text | |
PALM_KEY = "AIzaSyArKo4frsgJqoAiuJJ0GVsiIlDAjqD08z4" | |
cons = """ | |
-elaborate everything | |
-no repetations | |
-add naration | |
- 'Close up': | |
- 'Medium': | |
- 'Wide': | |
Begin your narration with these cues, and let the screenplay unfold based on the user's input. We want to experience the heart-pounding excitement of this crucial match, and you are our guide through this thrilling journey. | |
""" | |
def generate_text(prompt, length=500, genre=None): | |
url = "https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=" + PALM_KEY | |
headers = { | |
"Content-Type": "application/json", | |
} | |
payload = { | |
"prompt": { | |
"text": cons+prompt+f" Genre: {genre} Length: {length} words.", | |
}, | |
} | |
response = requests.post(url, headers=headers, json=payload) | |
response.raise_for_status() | |
response_json = response.json() | |
return response_json['candidates'][0]['output'] | |
def download_screenplay(screenplay): | |
filename = "generated_screenplay.txt" | |
with open(filename, "w", encoding="utf-8") as file: | |
file.write(screenplay) | |
def submit_feedback(feedback): | |
feedback_message = "Thank you for your feedback! We appreciate your input." | |
return feedback_message | |
demo = gr.Blocks( | |
css=""" | |
.gradio-container {background-color: beige;font-family: Roboto, sans-serif;}footer {visibility: hidden; } | |
.Markdown-body { color: visible;}""" | |
) | |
with demo: | |
gr.Markdown( | |
""" | |
<center><b><div style="font-size: 28px; color:#333333"> | |
A web based application which generates movie screenplay with the input of voice | |
</div></b></center> | |
""") | |
with gr.Tab("Audio to screenplay generation"): | |
demo.heading = "Problem statement: Generate a movie screenplay from an audio file." | |
audio_file = gr.Audio(type="filepath") | |
live=True | |
length = gr.Slider(label="Length in words", step=1) | |
genre = gr.Dropdown(label="Genre", choices=["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Horror", "Mystery", "Sci-Fi", "Thriller"]) | |
text = gr.Textbox(label="Speech to Text") | |
generated_screenplay = gr.Textbox(label="Required screenplay") | |
with gr.Row(): | |
b1 = gr.Button("CONVERT") | |
b2 = gr.Button("SCREENPLAY") | |
b3 = gr.Button("DOWNLOAD") | |
b1.click(speech_to_text, inputs=audio_file, outputs=text) | |
b2.click(generate_text, inputs=[text, length, genre], outputs=[generated_screenplay]) | |
b3.click(download_screenplay, inputs=[generated_screenplay]) | |
feedback = gr.Textbox(label="Feedback", placeholder="Share your feedback here") | |
feedback_button = gr.Button("Submit Feedback") | |
feedback_output = gr.Textbox(label="Feedback Status") | |
feedback_button.click(submit_feedback, inputs=[feedback], outputs=[feedback_output]) | |
demo.launch() |