SoSa123456 commited on
Commit
ca1e304
1 Parent(s): 4f5812d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -34
app.py CHANGED
@@ -1,22 +1,19 @@
1
- import warnings
2
- warnings.filterwarnings('ignore')
3
-
4
- import matplotlib as mpl
5
- mpl.rcParams["figure.dpi"] = 150
6
-
7
- from huggingface_hub import InferenceClient
8
  import gradio as gr
 
9
 
10
  # Initialize the language model
11
  generator = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
12
 
13
- def generate_script(host_name, listener_location, causes_climate_change="", co2_level=400, effects_climate_change="", sea_level_rise=2.0, warming_rate=1.5, 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 combating 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
 
@@ -32,31 +29,23 @@ def generate_script(host_name, listener_location, causes_climate_change="", co2_
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
- # Debug output to Gradio interface
38
- debug_output = f"Debug Information:\n{'='*20}\n"
39
- debug_output += f"Generated Script:\n{script}\n{'='*20}\n"
40
- debug_output += f"Word Counts per Section:\n{word_counts}\n{'='*20}\n"
41
-
42
- return script, debug_output
43
-
44
- # Create Gradio inputs with default values
45
- inputs = [
46
- gr.Textbox(label="Host Name", default=""),
47
- gr.Textbox(label="Listener Location", default=""),
48
- gr.Textbox(label="Causes Climate Change", default=""),
49
- gr.Number(label="CO2 Level", default=400),
50
- gr.Textbox(label="Effects Climate Change", default=""),
51
- gr.Number(label="Sea Level Rise", default=2.0),
52
- gr.Number(label="Warming Rate", default=1.5),
53
- gr.Textbox(label="Potential Solutions", default=""),
54
- gr.Textbox(label="Individual Role", default=""),
55
- gr.Textbox(label="Call To Action", default="")
56
- ]
57
-
58
- # Create Gradio interface
59
- iface = gr.Interface(fn=generate_script, inputs=inputs, outputs=["text", "text"])
60
 
61
  # Launch the interface
62
  iface.launch()
 
 
 
 
 
 
 
 
1
  import gradio as gr
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="John", listener_location="City", causes_climate_change="human activities",
8
+ co2_level=400, effects_climate_change="rising temperatures", sea_level_rise=0.1,
9
+ warming_rate=0.2, potential_solutions="renewable energy", individual_role="reduce carbon footprint",
10
+ call_to_action="act now"):
11
  # Variables
12
  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...
13
  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...
14
  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...
15
  POTENTIAL SOLUTIONS: But don't worry, there are solutions. {potential_solutions} are all steps we can take to mitigate these effects...
16
+ 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...
17
  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...
18
  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!"""
19
 
 
29
  # Check if any section exceeds the target word count
30
  for i, count in enumerate(word_counts):
31
  if count > 200:
32
+ print(f"Warning: Section {i + 1} exceeds the target word count. You may need to shorten this section.")
33
+
34
+ return script
35
+
36
+ # Create a Gradio interface with default values
37
+ iface = gr.Interface(fn=generate_script,
38
+ inputs=[gr.Textbox(label="Host Name", default="John"),
39
+ gr.Textbox(label="Listener Location", default="City"),
40
+ gr.Textbox(label="Causes Climate Change", default="human activities"),
41
+ gr.Number(label="CO2 Level", default=400),
42
+ gr.Textbox(label="Effects Climate Change", default="rising temperatures"),
43
+ gr.Number(label="Sea Level Rise", default=0.1),
44
+ gr.Number(label="Warming Rate", default=0.2),
45
+ gr.Textbox(label="Potential Solutions", default="renewable energy"),
46
+ gr.Textbox(label="Individual Role", default="reduce carbon footprint"),
47
+ gr.Textbox(label="Call To Action", default="act now")],
48
+ outputs="text")
 
 
 
 
 
 
 
 
49
 
50
  # Launch the interface
51
  iface.launch()