Spaces:
Runtime error
Runtime error
SoSa123456
commited on
Commit
•
1f03019
1
Parent(s):
56d9120
Update app.py
Browse files
app.py
CHANGED
@@ -4,58 +4,40 @@ warnings.filterwarnings('ignore')
|
|
4 |
import matplotlib as mpl
|
5 |
mpl.rcParams["figure.dpi"] = 150
|
6 |
|
7 |
-
from
|
8 |
import gradio as gr
|
9 |
|
10 |
# Initialize the language model
|
11 |
-
|
12 |
-
|
13 |
-
def
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
# Generate script
|
28 |
-
script = f"""
|
29 |
-
INTRODUCTION: '{get_response(f"{host_name}, good morning! This is {listener_location}'s local radio station. Today we're talking about an issue that affects us all - climate change. It's a pressing issue that requires our immediate attention...")}'
|
30 |
-
|
31 |
-
CAUSES OF CLIMATE CHANGE: '{get_response(f"The causes of climate change are {climate_data['causes']}. Today, the level of CO2 in our atmosphere is {climate_data['co2_level']}, which is concerning...")}'
|
32 |
-
|
33 |
-
EFFECTS OF CLIMATE CHANGE: '{get_response(f"These activities result in {climate_data['effects']}, leading to drastic changes in our environment. For instance, sea levels are rising at a rate of {hazard_data['sea_level_rise']} per year, and global temperatures are increasing at a rate of {hazard_data['warming_rate']} per decade...")}'
|
34 |
-
|
35 |
-
POTENTIAL SOLUTIONS: '{get_response(f"But don't worry, there are solutions. {climate_data['solutions']} are all steps we can take to mitigate these effects...")}'
|
36 |
-
|
37 |
-
INDIVIDUAL ROLE: '{get_response(f"Each one of us plays a role in combatting climate change. Even small actions can make a big difference. In fact, our location, {listener_location}, is particularly vulnerable to climate change due to its geographical features...")}'
|
38 |
-
|
39 |
-
CALL TO ACTION: '{get_response(f"So, {listener_location}, why wait? Start taking steps today towards a greener future. Support local businesses that prioritize sustainability, reduce your carbon footprint, and voice your opinion to policy makers...")}'
|
40 |
-
|
41 |
-
SUMMARY: '{get_response(f"In conclusion, climate change is a serious issue that requires our immediate attention. But by understanding its causes, effects, and potential solutions, we can all play a part in mitigating its impact. Thank you for joining us today, and remember, every small action counts!")}'
|
42 |
-
"""
|
43 |
-
|
44 |
-
# Split the script into sections
|
45 |
sections = script.split("\n")
|
46 |
|
47 |
-
# Calculate the word count for each section
|
48 |
-
word_counts = [
|
49 |
|
50 |
-
# Check if any section exceeds the target word count
|
51 |
-
for i, count in enumerate(word_counts):
|
52 |
-
|
53 |
print(f"Warning: Section {i+1} exceeds the target word count. You may need to shorten this section.")
|
54 |
|
55 |
-
return script
|
56 |
|
57 |
# Create a Gradio interface
|
58 |
-
iface = gr.Interface(fn=generate_script, inputs=["
|
59 |
|
60 |
# Launch the interface
|
61 |
-
iface.launch()
|
|
|
4 |
import matplotlib as mpl
|
5 |
mpl.rcParams["figure.dpi"] = 150
|
6 |
|
7 |
+
from transformers import pipeline
|
8 |
import gradio as gr
|
9 |
|
10 |
# Initialize the language model
|
11 |
+
generator = pipeline('text-generation', model='tiiuae/falcon-7b-instruct')
|
12 |
+
|
13 |
+
def generate_script(host_name, listener_location, causes_climate_change, co2_level, effects_climate_change, sea_level_rise, warming_rate, potential_solutions, individual_role, call_to_action):
|
14 |
+
# Variables
|
15 |
+
prompt_template = f"""INTRODUCTION: {host_name}, good morning! This is {listener_location}'s local radio station. Today we're talking about an issue that affects us all - climate change. It's a pressing issue that requires our immediate attention...
|
16 |
+
CAUSES OF CLIMATE CHANGE: The causes of climate change are {causes_climate_change}. Today, the level of CO2 in our atmosphere is {co2_level}, which is concerning...
|
17 |
+
EFFECTS OF CLIMATE CHANGE: These activities result in {effects_climate_change}, leading to drastic changes in our environment. For instance, sea levels are rising at a rate of {sea_level_rise} per year, and global temperatures are increasing at a rate of {warming_rate} per decade...
|
18 |
+
POTENTIAL SOLUTIONS: But don't worry, there are solutions. {potential_solutions} are all steps we can take to mitigate these effects...
|
19 |
+
INDIVIDUAL ROLE: Each one of us plays a role in combatting climate change. Even small actions can make a big difference. In fact, our location, {listener_location}, is particularly vulnerable to climate change due to its geographical features...
|
20 |
+
CALL TO ACTION: So, {listener_location}, why wait? Start taking steps today towards a greener future. Support local businesses that prioritize sustainability, reduce your carbon footprint, and voice your opinion to policy makers...
|
21 |
+
SUMMARY: In conclusion, climate change is a serious issue that requires our immediate attention. But by understanding its causes, effects, and potential solutions, we can all play a part in mitigating its impact. Thank you for joining us today, and remember, every small action counts!"""
|
22 |
+
|
23 |
+
# Generate the script
|
24 |
+
script = generator(prompt_template, max_length=1000)[0]['generated_text']
|
25 |
+
|
26 |
+
# Split the script into sections
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
sections = script.split("\n")
|
28 |
|
29 |
+
# Calculate the word count for each section
|
30 |
+
word_counts = [len(section.split()) for section in sections]
|
31 |
|
32 |
+
# Check if any section exceeds the target word count
|
33 |
+
for i, count in enumerate(word_counts):
|
34 |
+
if count > 200:
|
35 |
print(f"Warning: Section {i+1} exceeds the target word count. You may need to shorten this section.")
|
36 |
|
37 |
+
return script
|
38 |
|
39 |
# Create a Gradio interface
|
40 |
+
iface = gr.Interface(fn=generate_script, inputs=[gr.inputs.Textbox(label="Host Name"), gr.inputs.Textbox(label="Listener Location"), gr.inputs.Textbox(label="Causes Climate Change"), gr.inputs.Number(label="CO2 Level"), gr.inputs.Textbox(label="Effects Climate Change"), gr.inputs.Number(label="Sea Level Rise"), gr.inputs.Number(label="Warming Rate"), gr.inputs.Textbox(label="Potential Solutions"), gr.inputs.Textbox(label="Individual Role"), gr.inputs.Textbox(label="Call To Action")], outputs="text")
|
41 |
|
42 |
# Launch the interface
|
43 |
+
iface.launch()
|