RohitCSharp commited on
Commit
de17270
·
verified ·
1 Parent(s): f051d83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -11,6 +11,8 @@ import textwrap
11
  import random
12
  from urllib.request import urlretrieve
13
 
 
 
14
  # OpenAI LLM
15
  llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.3)
16
  summary_prompt = PromptTemplate.from_template("""
@@ -30,11 +32,19 @@ def extract_main_content(url):
30
  paras = [p.get_text() for p in soup.find_all("p") if len(p.get_text()) > 60]
31
  return "\n".join(paras[:20]) or None
32
 
 
 
 
 
 
 
 
 
 
33
  # Load external image assets
34
  ASSETS = {
35
  "logo": "https://huggingface.co/spaces/csccorner/Link-to-video/resolve/main/csharplogo.png",
36
- "bg": "https://img.freepik.com/free-photo/blue-abstract-gradient-wave-wallpaper_53876-102605.jpg",
37
- "graphic": "https://img.freepik.com/free-vector/startup-launch-concept-with-rocket_23-2147866180.jpg"
38
  }
39
 
40
  def download_asset(url):
@@ -47,8 +57,11 @@ def create_slides(text, duration, output_folder, max_lines=6):
47
  font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
48
  font = ImageFont.truetype(font_path, 48)
49
  logo_path = download_asset(ASSETS["logo"])
50
- bg_path = download_asset(ASSETS["bg"])
51
- graphic_path = download_asset(ASSETS["graphic"])
 
 
 
52
 
53
  chunks = textwrap.wrap(text, width=36)
54
  slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
@@ -130,9 +143,9 @@ iface = gr.Interface(
130
  gr.Textbox(label="Summary"),
131
  gr.Video(label="Generated AV Summary")
132
  ],
133
- title="🎞️ AV Summary Generator (Enhanced Slides with Background, Logo & Graphics)",
134
- description="Generates a 5/10 sec video summary from article URL with clean text, background visuals, C# Corner logo, and graphics."
135
  )
136
 
137
  if __name__ == '__main__':
138
- iface.launch()
 
11
  import random
12
  from urllib.request import urlretrieve
13
 
14
+ UNSPLASH_KEY = "-7tFgMCy_pwrouZrC8mmEIBpyskEyP25e3_Y4vWSvBs"
15
+
16
  # OpenAI LLM
17
  llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.3)
18
  summary_prompt = PromptTemplate.from_template("""
 
32
  paras = [p.get_text() for p in soup.find_all("p") if len(p.get_text()) > 60]
33
  return "\n".join(paras[:20]) or None
34
 
35
+ # Unsplash dynamic fetch
36
+ def fetch_unsplash_image(query):
37
+ url = f"https://api.unsplash.com/photos/random?query={query}&orientation=landscape&client_id={UNSPLASH_KEY}"
38
+ try:
39
+ resp = requests.get(url).json()
40
+ return resp['urls']['regular']
41
+ except:
42
+ return "https://img.freepik.com/free-photo/blue-abstract-gradient-wave-wallpaper_53876-102605.jpg"
43
+
44
  # Load external image assets
45
  ASSETS = {
46
  "logo": "https://huggingface.co/spaces/csccorner/Link-to-video/resolve/main/csharplogo.png",
47
+ "fallback_graphic": "https://img.freepik.com/free-vector/startup-launch-concept-with-rocket_23-2147866180.jpg"
 
48
  }
49
 
50
  def download_asset(url):
 
57
  font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
58
  font = ImageFont.truetype(font_path, 48)
59
  logo_path = download_asset(ASSETS["logo"])
60
+
61
+ graphic_query = random.choice(["technology", "startup", "ai", "innovation"])
62
+ bg_url = fetch_unsplash_image(graphic_query)
63
+ bg_path = download_asset(bg_url)
64
+ graphic_path = download_asset(ASSETS["fallback_graphic"])
65
 
66
  chunks = textwrap.wrap(text, width=36)
67
  slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
 
143
  gr.Textbox(label="Summary"),
144
  gr.Video(label="Generated AV Summary")
145
  ],
146
+ title="🎞️ AV Summary Generator (Visual Promo Style)",
147
+ description="Generates a 5/10 sec video summary from article URL with clean typography, dynamic Unsplash visuals, C# Corner logo, and illustrations."
148
  )
149
 
150
  if __name__ == '__main__':
151
+ iface.launch()