Spaces:
Runtime error
Runtime error
Commit ·
66a02d5
1
Parent(s): 899c09c
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,30 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
|
|
|
| 4 |
# Initialize the language model
|
| 5 |
generator = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 6 |
|
| 7 |
-
def generate_script(host_name
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
call_to_action="act now"):
|
| 11 |
# Variables
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
script = generator(prompt_template, max_length=1000)[0]['generated_text']
|
| 22 |
|
| 23 |
# Split the script into sections
|
|
@@ -33,15 +40,19 @@ def generate_script(host_name="John", listener_location="City", causes_climate_c
|
|
| 33 |
|
| 34 |
return script
|
| 35 |
|
| 36 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
iface = gr.Interface(fn=generate_script,
|
| 38 |
inputs=[gr.Textbox(label="Host Name", value="John"),
|
| 39 |
gr.Textbox(label="Listener Location", value="City"),
|
| 40 |
gr.Textbox(label="Causes Climate Change", value="human activities"),
|
| 41 |
-
gr.Number(label="CO2 Level",
|
| 42 |
gr.Textbox(label="Effects Climate Change", value="rising temperatures"),
|
| 43 |
-
gr.Number(label="Sea Level Rise",
|
| 44 |
-
gr.Number(label="Warming Rate",
|
| 45 |
gr.Textbox(label="Potential Solutions", value="renewable energy"),
|
| 46 |
gr.Textbox(label="Individual Role", value="reduce carbon footprint"),
|
| 47 |
gr.Textbox(label="Call To Action", value="act now")],
|
|
|
|
| 1 |
+
|
| 2 |
+
import warnings
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
warnings.filterwarnings('ignore')
|
| 6 |
+
|
| 7 |
# Initialize the language model
|
| 8 |
generator = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 9 |
|
| 10 |
+
def generate_script(host_name, listener_location, causes_climate_change, co2_level, effects_climate_change,
|
| 11 |
+
sea_level_rise, warming_rate, potential_solutions, individual_role, call_to_action,
|
| 12 |
+
TOPIC, DESCRIPTION):
|
|
|
|
| 13 |
# Variables
|
| 14 |
+
introduction_template = f"{host_name}, good morning! This is {listener_location}'s local radio station. Today we're talking about an issue that affects us all - {TOPIC}. It's a pressing issue that requires our immediate attention..."
|
| 15 |
+
causes_template = f"The causes of {TOPIC} are {causes_climate_change}. Today, the level of CO2 in our atmosphere is {co2_level}, which is concerning..."
|
| 16 |
+
effects_template = f"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..."
|
| 17 |
+
solutions_template = f"But don't worry, there are solutions. {potential_solutions} are all steps we can take to mitigate these effects..."
|
| 18 |
+
role_template = f"Each one of us plays a role in combating {TOPIC}. Even small actions can make a big difference. In fact, our location, {listener_location}, is particularly vulnerable to {TOPIC} due to its geographical features..."
|
| 19 |
+
action_template = 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..."
|
| 20 |
+
summary_template = f"In conclusion, {TOPIC} 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!"
|
| 21 |
+
|
| 22 |
+
# Combine templates based on the DESCRIPTION
|
| 23 |
+
prompt_template = f"""{introduction_template} {causes_template} {effects_template} {solutions_template} {role_template} {action_template} {summary_template}
|
| 24 |
+
|
| 25 |
+
TOPIC: {TOPIC}. DESCRIPTION: {DESCRIPTION}"""
|
| 26 |
+
|
| 27 |
+
# Generate the script using the language model
|
| 28 |
script = generator(prompt_template, max_length=1000)[0]['generated_text']
|
| 29 |
|
| 30 |
# Split the script into sections
|
|
|
|
| 40 |
|
| 41 |
return script
|
| 42 |
|
| 43 |
+
# Example usage
|
| 44 |
+
#generate_script("Host Name", "Listener Location", "Causes of Climate Change", 415, "Effects of Climate Change",
|
| 45 |
+
# 2.5, 1.5, "Potential Solutions", "Individual Role", "Call to Action", "Environmental Issues", "Description of the environmental issues")
|
| 46 |
+
|
| 47 |
+
|
| 48 |
iface = gr.Interface(fn=generate_script,
|
| 49 |
inputs=[gr.Textbox(label="Host Name", value="John"),
|
| 50 |
gr.Textbox(label="Listener Location", value="City"),
|
| 51 |
gr.Textbox(label="Causes Climate Change", value="human activities"),
|
| 52 |
+
gr.Number(label="CO2 Level", value=400),
|
| 53 |
gr.Textbox(label="Effects Climate Change", value="rising temperatures"),
|
| 54 |
+
gr.Number(label="Sea Level Rise", value=0.1),
|
| 55 |
+
gr.Number(label="Warming Rate", value=0.2),
|
| 56 |
gr.Textbox(label="Potential Solutions", value="renewable energy"),
|
| 57 |
gr.Textbox(label="Individual Role", value="reduce carbon footprint"),
|
| 58 |
gr.Textbox(label="Call To Action", value="act now")],
|