Kajise commited on
Commit
bf23d89
·
1 Parent(s): 0c2d943

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -0
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ from selenium import webdriver
3
+ from typing import Iterable
4
+
5
+ import re
6
+ import os
7
+ import gradio as Gradio
8
+ from gradio.themes.base import Base
9
+ from gradio.themes.utils import colors, fonts
10
+
11
+
12
+ theme = Gradio.themes.Monochrome(
13
+ primary_hue="purple",
14
+ secondary_hue="purple",
15
+ neutral_hue="neutral",
16
+ radius_size=Gradio.themes.sizes.radius_sm,
17
+ font=[Gradio.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
18
+ )
19
+
20
+ class PurpleTheme(Base):
21
+ def __init__(
22
+ self,
23
+ *,
24
+ primary_hue: colors.Color | str = colors.purple,
25
+ secondary_hue: colors.Color | str = colors.purple,
26
+ neutral_hue: colors.Color | str = colors.neutral,
27
+ spacing_size: sizes.Size | str = sizes.spacing_md,
28
+ radius_size: sizes.Size | str = sizes.radius_md,
29
+ font: fonts.Font
30
+ | str
31
+ | Iterable[fonts.Font | str] = (
32
+ fonts.GoogleFont("Inter"),
33
+ "ui-sans-serif",
34
+ "sans-serif",
35
+ ),
36
+ font_mono: fonts.Font
37
+ | str
38
+ | Iterable[fonts.Font | str] = (
39
+ fonts.GoogleFont("Space Grotesk"),
40
+ "ui-monospace",
41
+ "monospace",
42
+ ),
43
+ ):
44
+ super().__init__(
45
+ primary_hue=primary_hue,
46
+ secondary_hue=secondary_hue,
47
+ neutral_hue=neutral_hue,
48
+ spacing_size=spacing_size,
49
+ radius_size=radius_size,
50
+ font=font,
51
+ font_mono=font_mono,
52
+ )
53
+ super().set(
54
+ button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
55
+ button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
56
+ button_primary_text_color="white",
57
+ button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
58
+ block_shadow="*shadow_drop_lg",
59
+ button_shadow="*shadow_drop_lg",
60
+ input_background_fill="zinc",
61
+ input_border_color="*secondary_300",
62
+ input_shadow="*shadow_drop",
63
+ input_shadow_focus="*shadow_drop_lg",
64
+ )
65
+
66
+ custom_theme = PurpleTheme()
67
+
68
+ title = "Imaginor"
69
+ driver_type = 'chromedriver'
70
+ description = "Imaginor is a small space for taking screenshots of websites."
71
+
72
+ def run_imaginor(text: str):
73
+ driver = webdriver.Chrome(driver_type)
74
+ driver.get(text)
75
+ screenshot = driver.save_screenshot('./site_screenshot.png')
76
+ driver.quit()
77
+
78
+ if not os.path.isfile('./site_screenshot.png'):
79
+ return ['./site_screenshot.png', 'Website imagined by Imaginor, operation success.']
80
+ else:
81
+ return [None, 'Website imagined by Imaginor, operation failed.']
82
+
83
+ Gradio.Interface(
84
+ run_imaginor,
85
+ Gradio.Textbox(placeholder="Enter your URL here", label="Website URL / Endpoint"),
86
+ [Gradio.Image(type="filepath", "Screenshot"),
87
+ Gradio.Textbox(label="Text result", interactive=False)],
88
+ title=title,
89
+ description=description,
90
+ theme=custom_theme,
91
+ analytics_enabled=False,
92
+ css=".generating {visibility: hidden}"
93
+ ).launch(enable_queue=True)