Spaces:
Runtime error
Runtime error
shivaninuji
commited on
Commit
•
3774a24
1
Parent(s):
2f66d6b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install gradio
|
2 |
+
!pip install transformers
|
3 |
+
!pip install pipeline
|
4 |
+
import gradio as gr
|
5 |
+
from transformers import pipeline
|
6 |
+
import requests
|
7 |
+
import os
|
8 |
+
from IPython.display import FileLink, HTML, display
|
9 |
+
import time
|
10 |
+
|
11 |
+
|
12 |
+
asr = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
|
13 |
+
|
14 |
+
def download_screenplay(screenplay):
|
15 |
+
filename = "generated_screenplay.txt"
|
16 |
+
with open(filename, "w", encoding="utf-8") as file:
|
17 |
+
file.write(screenplay)
|
18 |
+
display(HTML(f'<a href="{filename}" download>Download Screenplay</a>'))
|
19 |
+
|
20 |
+
def speech_to_text(speech):
|
21 |
+
text = asr(speech)["text"]
|
22 |
+
return text
|
23 |
+
|
24 |
+
|
25 |
+
PALM_KEY = "AIzaSyArKo4frsgJqoAiuJJ0GVsiIlDAjqD08z4"
|
26 |
+
cons = """
|
27 |
+
-elaborate everything
|
28 |
+
-no repetations
|
29 |
+
-add naration
|
30 |
+
- 'Close up':
|
31 |
+
- 'Medium':
|
32 |
+
- 'Wide':
|
33 |
+
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.
|
34 |
+
"""
|
35 |
+
|
36 |
+
def generate_text(prompt, length=500, genre=None):
|
37 |
+
url = "https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=" + PALM_KEY
|
38 |
+
headers = {
|
39 |
+
"Content-Type": "application/json",
|
40 |
+
}
|
41 |
+
payload = {
|
42 |
+
"prompt": {
|
43 |
+
"text": cons+prompt+f" Genre: {genre} Length: {length} words.",
|
44 |
+
},
|
45 |
+
}
|
46 |
+
response = requests.post(url, headers=headers, json=payload)
|
47 |
+
response.raise_for_status()
|
48 |
+
response_json = response.json()
|
49 |
+
return response_json['candidates'][0]['output']
|
50 |
+
|
51 |
+
|
52 |
+
def download_screenplay(screenplay):
|
53 |
+
filename = "generated_screenplay.txt"
|
54 |
+
with open(filename, "w", encoding="utf-8") as file:
|
55 |
+
file.write(screenplay)
|
56 |
+
|
57 |
+
def submit_feedback(feedback):
|
58 |
+
feedback_message = "Thank you for your feedback! We appreciate your input."
|
59 |
+
return feedback_message
|
60 |
+
|
61 |
+
|
62 |
+
demo = gr.Blocks(
|
63 |
+
css="""
|
64 |
+
.gradio-container {background-color: beige;font-family: Roboto, sans-serif;}footer {visibility: hidden; }
|
65 |
+
.Markdown-body { color: visible;}"""
|
66 |
+
)
|
67 |
+
|
68 |
+
with demo:
|
69 |
+
gr.Markdown(
|
70 |
+
"""
|
71 |
+
<center><b><div style="font-size: 28px; color:#333333">
|
72 |
+
A web based application which generates movie screenplay with the input of voice
|
73 |
+
</div></b></center>
|
74 |
+
""")
|
75 |
+
with gr.Tab("Audio to screenplay generation"):
|
76 |
+
demo.heading = "Problem statement: Generate a movie screenplay from an audio file."
|
77 |
+
audio_file = gr.Audio(type="filepath")
|
78 |
+
live=True
|
79 |
+
length = gr.Slider(label="Length in words", step=1)
|
80 |
+
genre = gr.Dropdown(label="Genre", choices=["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Horror", "Mystery", "Sci-Fi", "Thriller"])
|
81 |
+
text = gr.Textbox(label="Speech to Text")
|
82 |
+
generated_screenplay = gr.Textbox(label="Required screenplay")
|
83 |
+
|
84 |
+
|
85 |
+
with gr.Row():
|
86 |
+
b1 = gr.Button("CONVERT")
|
87 |
+
b2 = gr.Button("SCREENPLAY")
|
88 |
+
b3 = gr.Button("DOWNLOAD")
|
89 |
+
|
90 |
+
|
91 |
+
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
92 |
+
b2.click(generate_text, inputs=[text, length, genre], outputs=[generated_screenplay])
|
93 |
+
b3.click(download_screenplay, inputs=[generated_screenplay])
|
94 |
+
|
95 |
+
feedback = gr.Textbox(label="Feedback", placeholder="Share your feedback here")
|
96 |
+
feedback_button = gr.Button("Submit Feedback")
|
97 |
+
feedback_output = gr.Textbox(label="Feedback Status")
|
98 |
+
feedback_button.click(submit_feedback, inputs=[feedback], outputs=[feedback_output])
|
99 |
+
|
100 |
+
|
101 |
+
demo.launch()
|