File size: 3,289 Bytes
3774a24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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()