AliDaud commited on
Commit
8f96f85
ยท
verified ยท
1 Parent(s): 619bd18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -34
app.py CHANGED
@@ -12,7 +12,7 @@ HEADERS = {
12
  "Content-Type": "application/json"
13
  }
14
 
15
- # === FILTER SETUP ===
16
  BLOCKED_KEYWORDS = [
17
  "sex", "drugs", "violence", "suicide", "death", "kill", "murder", "gun",
18
  "abuse", "politics", "terror", "crime", "war", "religion", "racism",
@@ -30,17 +30,12 @@ You are a scriptwriter for an educational podcast aimed at school students in gr
30
 
31
  Create a short and engaging podcast script on the topic: "{topic}".
32
 
33
- Two hosts, Host 1 and Host 2, should have a back-and-forth conversation about the topic.
 
34
  The tone should be friendly, easy to understand, and informative.
35
- Avoid complex jargon and make it suitable for students aged 13โ€“18.
36
 
37
- Use the format:
38
- Host 1: ...
39
- Host 2: ...
40
- ...
41
-
42
- Make sure the conversation stays focused, clear, and ends in under 800 words.
43
- Avoid going off-topic or repeating points.
44
  """
45
 
46
  data = {
@@ -62,13 +57,17 @@ Avoid going off-topic or repeating points.
62
 
63
  # === FORMAT SCRIPT CLEANLY FOR DISPLAY ===
64
  def format_script(script: str) -> str:
65
- import re
66
-
67
  # Remove markdown bolding like **text**
68
  script = re.sub(r'\*\*(.*?)\*\*', r'\1', script)
69
 
70
- # Remove intro/outro music lines or similar direction text
71
- script = re.sub(r'(?i)^.*music.*$', '', script, flags=re.MULTILINE)
 
 
 
 
 
 
72
 
73
  lines = script.strip().split("\n")
74
  formatted = ""
@@ -77,46 +76,62 @@ def format_script(script: str) -> str:
77
  line = line.strip()
78
  if not line:
79
  continue
80
- if line.startswith("Host 1:"):
81
- content = line.replace("Host 1:", "").strip()
82
- formatted += f"<div class='host1'> <b>Host 1:</b> {content}</div>\n"
83
- elif line.startswith("Host 2:"):
84
- content = line.replace("Host 2:", "").strip()
85
- formatted += f"<div class='host2'> <b>Host 2:</b> {content}</div>\n"
86
  else:
87
  formatted += f"<div class='narration'>{line}</div>\n"
88
 
89
  return formatted
90
 
91
- # === FINAL APP FUNCTION ===
92
  def generate(topic):
93
  if not is_safe_topic(topic):
94
  return "<b style='color:red;'>โš ๏ธ Restricted content. Please enter an appropriate educational topic.</b>"
95
  raw_script = generate_educational_podcast(topic)
96
  return format_script(raw_script)
97
 
98
- # === GLOSSY CSS STYLING ===
99
  custom_css = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  .host1, .host2 {
101
  border-radius: 16px;
102
  padding: 14px;
103
  margin: 16px 0;
104
- box-shadow: 0 4px 10px rgba(0,0,0,0.1);
105
  font-size: 16px;
106
  line-height: 1.6;
 
107
  }
108
 
109
- # .host1 {
110
- # background: linear-gradient(135deg, #d0e8ff, #e6f3ff);
111
- # }
112
 
113
- # .host2 {
114
- # background: linear-gradient(135deg, #ffe6f0, #fce8ff);
115
- # }
116
 
117
  .narration {
118
  font-style: italic;
119
- color: #555;
120
  margin: 10px 0;
121
  font-size: 15px;
122
  }
@@ -124,14 +139,13 @@ custom_css = """
124
 
125
  # === GRADIO INTERFACE ===
126
  with gr.Blocks(css=custom_css) as demo:
127
- gr.Markdown("## ๐ŸŽ“ Educational Podcast Generator for Students")
128
- gr.Markdown("Enter an educational topic, and get a podcast-style conversation between two friendly hosts!")
129
 
130
  topic_input = gr.Textbox(label="Enter educational topic")
131
- generate_btn = gr.Button("๐ŸŽ™๏ธ Generate Podcast")
132
  output_box = gr.HTML()
133
 
134
  generate_btn.click(fn=generate, inputs=topic_input, outputs=output_box)
135
 
136
- # === LAUNCH ===
137
  demo.launch()
 
12
  "Content-Type": "application/json"
13
  }
14
 
15
+ # === BLOCK INAPPROPRIATE CONTENT ===
16
  BLOCKED_KEYWORDS = [
17
  "sex", "drugs", "violence", "suicide", "death", "kill", "murder", "gun",
18
  "abuse", "politics", "terror", "crime", "war", "religion", "racism",
 
30
 
31
  Create a short and engaging podcast script on the topic: "{topic}".
32
 
33
+ The two hosts are named Ali and Talha. Ali starts the conversation.
34
+ They should have a back-and-forth conversation about the topic.
35
  The tone should be friendly, easy to understand, and informative.
 
36
 
37
+ Avoid music or sound effects. Keep the total length under 800 words.
38
+ Only write their dialogue and a few narration lines if needed. Do NOT use Host 1/2 or any generic names.
 
 
 
 
 
39
  """
40
 
41
  data = {
 
57
 
58
  # === FORMAT SCRIPT CLEANLY FOR DISPLAY ===
59
  def format_script(script: str) -> str:
 
 
60
  # Remove markdown bolding like **text**
61
  script = re.sub(r'\*\*(.*?)\*\*', r'\1', script)
62
 
63
+ # Remove music and direction lines
64
+ script = re.sub(r'(?i)^.*(music|sound effect).*$','', script, flags=re.MULTILINE)
65
+
66
+ # Normalize host names to Ali and Talha
67
+ script = script.replace("Host 1:", "Ali:")
68
+ script = script.replace("Host 2:", "Talha:")
69
+ script = re.sub(r'\b[Aa]lex:', 'Ali:', script)
70
+ script = re.sub(r'\b[Mm]aya:', 'Talha:', script)
71
 
72
  lines = script.strip().split("\n")
73
  formatted = ""
 
76
  line = line.strip()
77
  if not line:
78
  continue
79
+ if line.startswith("Ali:"):
80
+ content = line.replace("Ali:", "").strip()
81
+ formatted += f"<div class='host1'>๐ŸŽ™๏ธ <b>Ali:</b> {content}</div>\n"
82
+ elif line.startswith("Talha:"):
83
+ content = line.replace("Talha:", "").strip()
84
+ formatted += f"<div class='host2'>๐ŸŽง <b>Talha:</b> {content}</div>\n"
85
  else:
86
  formatted += f"<div class='narration'>{line}</div>\n"
87
 
88
  return formatted
89
 
90
+ # === FINAL FUNCTION ===
91
  def generate(topic):
92
  if not is_safe_topic(topic):
93
  return "<b style='color:red;'>โš ๏ธ Restricted content. Please enter an appropriate educational topic.</b>"
94
  raw_script = generate_educational_podcast(topic)
95
  return format_script(raw_script)
96
 
97
+ # === DARK GLOSSY CSS ===
98
  custom_css = """
99
+ # body {
100
+ # background-color: darkslateblue !important;
101
+ # color: #ffffff;
102
+ # }
103
+
104
+ # .gradio-container {
105
+ # background-color: darkslateblue !important;
106
+ # }
107
+
108
+ # textarea, input, .gr-button {
109
+ # background-color: darkslategray !important;
110
+ # color: #ffffff !important;
111
+ # border: 1px solid #aaa !important;
112
+ # }
113
+
114
  .host1, .host2 {
115
  border-radius: 16px;
116
  padding: 14px;
117
  margin: 16px 0;
118
+ box-shadow: 0 4px 10px rgba(255,255,255,0.2);
119
  font-size: 16px;
120
  line-height: 1.6;
121
+ color: #ffffff;
122
  }
123
 
124
+ .host1 {
125
+ background: linear-gradient(135deg, #4b6cb7, #182848); /* Dark blue gradient */
126
+ }
127
 
128
+ .host2 {
129
+ background: linear-gradient(135deg, #2c3e50, #4ca1af); /* Slate gray gradient */
130
+ }
131
 
132
  .narration {
133
  font-style: italic;
134
+ color: #cccccc;
135
  margin: 10px 0;
136
  font-size: 15px;
137
  }
 
139
 
140
  # === GRADIO INTERFACE ===
141
  with gr.Blocks(css=custom_css) as demo:
142
+ gr.Markdown("## ๐ŸŽ™๏ธ Educational Podcast Generator with Ali & Talha", elem_id="title")
143
+ gr.Markdown("Enter an educational topic, and enjoy a friendly podcast conversation between Ali and Talha.")
144
 
145
  topic_input = gr.Textbox(label="Enter educational topic")
146
+ generate_btn = gr.Button("๐ŸŽง Generate Podcast")
147
  output_box = gr.HTML()
148
 
149
  generate_btn.click(fn=generate, inputs=topic_input, outputs=output_box)
150
 
 
151
  demo.launch()