Spaces:
Runtime error
Runtime error
Commit
·
91f81f0
1
Parent(s):
90ea0da
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
warnings.filterwarnings('ignore')
|
| 3 |
+
|
| 4 |
+
import matplotlib as mpl
|
| 5 |
+
mpl.rcParams["figure.dpi"] = 150
|
| 6 |
+
|
| 7 |
+
from langchain import HuggingFaceHub
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
# Initialize the language model
|
| 11 |
+
llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature":0.6})
|
| 12 |
+
|
| 13 |
+
def get_response(prompt):
|
| 14 |
+
# Generate a response from the language model
|
| 15 |
+
response = llm(prompt)
|
| 16 |
+
|
| 17 |
+
# Return the response
|
| 18 |
+
return response
|
| 19 |
+
|
| 20 |
+
def word_count(section):
|
| 21 |
+
# Count the number of words in a section
|
| 22 |
+
return len(section.split())
|
| 23 |
+
|
| 24 |
+
def generate_script(host_name, listener_location, climate_data, hazard_data):
|
| 25 |
+
# Variables
|
| 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 = [word_count(section) for section in sections]
|
| 49 |
+
|
| 50 |
+
# Check if any section exceeds the target word count
|
| 51 |
+
for i, count in enumerate(word_counts):
|
| 52 |
+
if count > 200:
|
| 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=["text", "text", gr.JSON(), gr.JSON()], outputs="text")
|
| 59 |
+
|
| 60 |
+
# Launch the interface
|
| 61 |
+
iface.launch()
|
| 62 |
+
|