John6666 commited on
Commit
2d08364
Β·
verified Β·
1 Parent(s): a3dbdfb

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +13 -12
  2. app.py +181 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,13 @@
1
- ---
2
- title: Test Vercel
3
- emoji: πŸš€
4
- colorFrom: pink
5
- colorTo: blue
6
- sdk: gradio
7
- sdk_version: 5.49.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
+ ---
2
+ title: test vercel
3
+ emoji: πŸ™„
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 4.44.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import requests
4
+ import socket
5
+ from urllib.parse import urlparse
6
+ import traceback
7
+
8
+ DEFAULT_TEST_URL = "https://realfavicongenerator.net/api/v2"
9
+ DEFAULT_RFG_ANALYSIS_ENDPOINT = "https://realfavicongenerator.net/api/v2/favicons/analysis"
10
+
11
+
12
+ def normalize_url(url: str) -> str:
13
+ url = (url or "").strip()
14
+ if not url:
15
+ return ""
16
+ if not url.startswith(("http://", "https://")):
17
+ url = "https://" + url
18
+ return url
19
+
20
+
21
+ def ping_url(url: str, method: str = "GET", timeout_sec: float = 10.0) -> str:
22
+ url = normalize_url(url)
23
+ if not url:
24
+ return "ERROR: URL is empty"
25
+
26
+ try:
27
+ resp = requests.request(method=method, url=url, timeout=timeout_sec)
28
+ lines = [
29
+ f"Request: {method} {url}",
30
+ f"Status code: {resp.status_code}",
31
+ f"Elapsed: {resp.elapsed.total_seconds():.3f} seconds",
32
+ "",
33
+ "=== Response headers ===",
34
+ ]
35
+ for k, v in resp.headers.items():
36
+ lines.append(f"{k}: {v}")
37
+ lines.extend(
38
+ [
39
+ "",
40
+ "=== First 1000 characters of body ===",
41
+ resp.text[:1000],
42
+ ]
43
+ )
44
+ return "\n".join(lines)
45
+ except Exception as e:
46
+ return "ERROR while calling URL: " + repr(e) + "\n\n" + traceback.format_exc()
47
+
48
+
49
+ def resolve_domain(target: str) -> str:
50
+ target = (target or "").strip()
51
+ if not target:
52
+ return "ERROR: Empty input"
53
+
54
+ if "://" in target:
55
+ hostname = urlparse(target).hostname or target
56
+ else:
57
+ hostname = target
58
+
59
+ try:
60
+ infos = socket.getaddrinfo(hostname, None)
61
+ ips = sorted({item[4][0] for item in infos})
62
+ lines = [
63
+ f"Input: {target}",
64
+ f"Hostname: {hostname}",
65
+ "",
66
+ "Resolved IP addresses:",
67
+ ]
68
+ if ips:
69
+ lines.extend(ips)
70
+ else:
71
+ lines.append("(no IPs returned)")
72
+ return "\n".join(lines)
73
+ except Exception as e:
74
+ return "ERROR while resolving domain: " + repr(e) + "\n\n" + traceback.format_exc()
75
+
76
+
77
+ def test_rfg_analysis(site_url: str, timeout_sec: float = 25.0) -> str:
78
+ site_url = normalize_url(site_url)
79
+ if not site_url:
80
+ return "ERROR: Website URL is empty"
81
+
82
+ api = DEFAULT_RFG_ANALYSIS_ENDPOINT
83
+ try:
84
+ resp = requests.get(api, params={"url": site_url}, timeout=timeout_sec)
85
+ lines = [
86
+ f"Request: GET {api}",
87
+ f"Query param url={site_url}",
88
+ f"Status code: {resp.status_code}",
89
+ f"Elapsed: {resp.elapsed.total_seconds():.3f} seconds",
90
+ "",
91
+ "=== First 2000 characters of JSON/text body ===",
92
+ resp.text[:2000],
93
+ ]
94
+ return "\n".join(lines)
95
+ except Exception as e:
96
+ return "ERROR while calling RealFaviconGenerator analysis API: " + repr(e) + "\n\n" + traceback.format_exc()
97
+
98
+
99
+ with gr.Blocks() as demo:
100
+ gr.Markdown(
101
+ """
102
+ # Minimal network test Space
103
+
104
+ This Space is designed to test outbound connectivity from Hugging Face
105
+ Spaces to arbitrary HTTPS endpoints, including the RealFaviconGenerator
106
+ API hosted on Vercel.
107
+
108
+ Use the tabs below to:
109
+ - Ping any HTTPS URL (GET/HEAD) and inspect status, latency and headers.
110
+ - Resolve a domain to its IP addresses.
111
+ - Call the RealFaviconGenerator analysis API directly.
112
+ """
113
+ )
114
+
115
+ with gr.Tab("Ping website"):
116
+ url_in = gr.Textbox(
117
+ label="URL",
118
+ value="https://realfavicongenerator.net/api/v2",
119
+ placeholder="https://example.com",
120
+ )
121
+ method = gr.Dropdown(
122
+ ["GET", "HEAD"],
123
+ value="GET",
124
+ label="HTTP method",
125
+ )
126
+ timeout = gr.Slider(
127
+ minimum=1,
128
+ maximum=60,
129
+ value=10,
130
+ step=1,
131
+ label="Timeout (seconds)",
132
+ )
133
+ ping_out = gr.Textbox(
134
+ label="Result",
135
+ lines=22,
136
+ show_copy_button=True,
137
+ )
138
+ ping_btn = gr.Button("Ping URL")
139
+ ping_btn.click(ping_url, inputs=[url_in, method, timeout], outputs=ping_out)
140
+
141
+ with gr.Tab("Resolve domain"):
142
+ domain_in = gr.Textbox(
143
+ label="Domain or URL",
144
+ value="realfavicongenerator.net",
145
+ placeholder="example.com or https://example.com",
146
+ )
147
+ resolve_out = gr.Textbox(
148
+ label="Resolution result",
149
+ lines=14,
150
+ show_copy_button=True,
151
+ )
152
+ resolve_btn = gr.Button("Resolve")
153
+ resolve_btn.click(resolve_domain, inputs=domain_in, outputs=resolve_out)
154
+
155
+ with gr.Tab("RealFaviconGenerator analysis"):
156
+ site_url_in = gr.Textbox(
157
+ label="Website URL to analyze",
158
+ value="https://example.com",
159
+ placeholder="https://example.com",
160
+ )
161
+ rfg_timeout = gr.Slider(
162
+ minimum=5,
163
+ maximum=60,
164
+ value=25,
165
+ step=1,
166
+ label="Timeout (seconds)",
167
+ )
168
+ rfg_out = gr.Textbox(
169
+ label="RFG API response / error",
170
+ lines=24,
171
+ show_copy_button=True,
172
+ )
173
+ rfg_btn = gr.Button("Call RFG analysis API")
174
+ rfg_btn.click(
175
+ test_rfg_analysis,
176
+ inputs=[site_url_in, rfg_timeout],
177
+ outputs=rfg_out,
178
+ )
179
+
180
+ if __name__ == "__main__":
181
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #gradio==4.44.0
2
+ requests>=2.31.0
3
+ pydantic==2.10.6