prointerv commited on
Commit
ccd8e49
ยท
verified ยท
1 Parent(s): 2839c55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -21
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import requests
3
  from bs4 import BeautifulSoup
4
 
 
5
  def get_epic_free_games():
6
  try:
7
  url = "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=en-US"
@@ -18,11 +19,12 @@ def get_epic_free_games():
18
  slug = game.get("productSlug", "")
19
  if slug:
20
  link = f"https://store.epicgames.com/p/{slug}"
21
- results.append(f"- {title} (Free {start} to {end}) โ†’ {link}")
22
  return results if results else ["No free games on Epic today."]
23
  except Exception as e:
24
- return [f"Error fetching Epic Games: {e}"]
25
 
 
26
  def get_steam_games():
27
  try:
28
  url = "https://isthereanydeal.com/giveaways/"
@@ -31,6 +33,7 @@ def get_steam_games():
31
  soup = BeautifulSoup(res.text, "html.parser")
32
  game_blocks = soup.find_all("div", class_="giveaway")
33
  steam_data = []
 
34
  for block in game_blocks[:5]:
35
  title = block.find("div", class_="title").text.strip()
36
  link = block.find("a", href=True)["href"]
@@ -48,30 +51,43 @@ def get_steam_games():
48
  except Exception as e:
49
  return [("https://cdn.cloudflare.steamstatic.com/steam/apps/0/header.jpg", f"Steam error: {e}")]
50
 
51
- def generate_game_summary():
52
- steam_games = get_steam_games()
53
- epic_games = get_epic_free_games()
 
54
 
55
- summary_text = "๐ŸŽฎ Epic Games:\n" + "\n".join(epic_games) + "\n\n" + \
56
- "๐ŸŸข Steam Games:\n" + "\n".join([info for _, info in steam_games])
57
 
58
- # Write to file
59
  with open("free_games.txt", "w", encoding="utf-8") as f:
60
- f.write(summary_text)
61
 
62
- # Return only image URLs for gallery
63
- steam_images = [img for img, _ in steam_games]
64
- return steam_images, summary_text, "free_games.txt"
65
 
66
- # Gradio UI
67
- with gr.Blocks() as demo:
68
- gr.Markdown("## ๐ŸŽ Free Game Finder โ€” Epic + Steam")
69
- button = gr.Button("Check Free Games")
70
- gallery = gr.Gallery(label="Steam Games", show_label=True, columns=2)
71
- summary = gr.Textbox(label="Game Summary", lines=20)
72
- file = gr.File(label="Download as TXT")
73
 
74
- button.click(fn=generate_game_summary, inputs=[], outputs=[gallery, summary, file])
 
75
 
76
- demo.launch()
 
 
 
 
 
 
 
77
 
 
 
 
 
 
 
 
2
  import requests
3
  from bs4 import BeautifulSoup
4
 
5
+ # Epic Games
6
  def get_epic_free_games():
7
  try:
8
  url = "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=en-US"
 
19
  slug = game.get("productSlug", "")
20
  if slug:
21
  link = f"https://store.epicgames.com/p/{slug}"
22
+ results.append(f"๐ŸŽฎ {title} (Free {start} to {end}) โ†’ {link}")
23
  return results if results else ["No free games on Epic today."]
24
  except Exception as e:
25
+ return [f"โŒ Error fetching Epic Games: {e}"]
26
 
27
+ # Steam Games + Images
28
  def get_steam_games():
29
  try:
30
  url = "https://isthereanydeal.com/giveaways/"
 
33
  soup = BeautifulSoup(res.text, "html.parser")
34
  game_blocks = soup.find_all("div", class_="giveaway")
35
  steam_data = []
36
+
37
  for block in game_blocks[:5]:
38
  title = block.find("div", class_="title").text.strip()
39
  link = block.find("a", href=True)["href"]
 
51
  except Exception as e:
52
  return [("https://cdn.cloudflare.steamstatic.com/steam/apps/0/header.jpg", f"Steam error: {e}")]
53
 
54
+ # Combine and Save
55
+ def generate_free_game_data():
56
+ epic = get_epic_free_games()
57
+ steam = get_steam_games()
58
 
59
+ txt = "๐ŸŽฎ Epic Games:\n" + "\n".join(epic) + "\n\n" + \
60
+ "๐ŸŸข Steam:\n" + "\n".join([info for _, info in steam])
61
 
 
62
  with open("free_games.txt", "w", encoding="utf-8") as f:
63
+ f.write(txt)
64
 
65
+ steam_imgs = [img for img, _ in steam]
66
+ return steam_imgs, txt, "free_games.txt"
 
67
 
68
+ # UI with Nice Design
69
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
70
+ gr.Markdown("""
71
+ # ๐Ÿ•น๏ธ **Free Game Radar**
72
+ Stay updated with the latest **limited-time free games** from:
73
+ - ๐ŸŽฎ Epic Games Store
74
+ - ๐ŸŸข Steam giveaways
75
 
76
+ Click the button below to scan today's free offers ๐Ÿ‘‡
77
+ """)
78
 
79
+ with gr.Row():
80
+ check_button = gr.Button("๐Ÿš€ Check Free Games", scale=2, variant="primary")
81
+
82
+ with gr.Row():
83
+ gallery = gr.Gallery(label="๐ŸŸข Steam Game Covers", show_label=True, columns=2).style(height="auto")
84
+
85
+ with gr.Row():
86
+ summary = gr.Textbox(label="๐Ÿ“ Game Summary", lines=20, interactive=False)
87
 
88
+ with gr.Row():
89
+ download = gr.File(label="โฌ‡๏ธ Download Game List")
90
+
91
+ check_button.click(fn=generate_free_game_data, inputs=[], outputs=[gallery, summary, download])
92
+
93
+ demo.launch()