@@ -62,111 +62,95 @@ <h1 style="font-size: 20px; font-weight: bold; margin-bottom: 12px; font-family:
6262 < a href ="https://sudo-soldier-pytr.hf.space " target ="_blank " rel ="noopener noreferrer "> on huggingface.co</ a >
6363 </ footer >
6464
65- < script >
66- const REDIS_URL = "https://amused-walleye-31373.upstash.io" ;
67- const REDIS_TOKEN = "AXqNASQgMWZmMTdjYTEtNTJjYi00MDczLWJmZDctNjFjZGUyOTA0ZjEyNjcyMTI0NDM2MDBjNDVmZmE5NjJlMTllYTkyMDI2MDU=" ;
68-
69- async function updateRingtoneCount ( ) {
70- try {
71- const response = await fetch ( ` ${ REDIS_URL } /get/ringtone_count` , { headers : { Authorization : `Bearer ${ REDIS_TOKEN } ` } } ) ;
72- const data = await response . json ( ) ;
73- document . getElementById ( "ringtone-count" ) . innerText = data . result || 0 ;
74- } catch ( error ) {
75- console . error ( "Error fetching ringtone count:" , error ) ;
76- }
65+ < script >
66+ const REDIS_URL = "https://amused-walleye-31373.upstash.io" ;
67+ const REDIS_TOKEN = "AXqNASQgMWZmMTdjYTEtNTJjYi00MDczLWJmZDctNjFjZGUyOTA0ZjEyNjcyMTI0NDM2MDBjNDVmZmE5NjJlMTllYTkyMDI2MDU=" ;
68+
69+ // Update ringtone count from Redis
70+ async function updateRingtoneCount ( ) {
71+ try {
72+ const response = await fetch ( ` ${ REDIS_URL } /get/ringtone_count` , { headers : { Authorization : `Bearer ${ REDIS_TOKEN } ` } } ) ;
73+ const data = await response . json ( ) ;
74+ document . getElementById ( "ringtone-count" ) . innerText = data . result || 0 ;
75+ } catch ( error ) {
76+ console . error ( "Error fetching ringtone count:" , error ) ;
7777 }
78+ }
7879
79- async function incrementRingtoneCount ( ) {
80- try {
81- await fetch ( ` ${ REDIS_URL } /incr/ringtone_count` , { headers : { Authorization : `Bearer ${ REDIS_TOKEN } ` } } ) ;
82- updateRingtoneCount ( ) ;
83- } catch ( error ) {
84- console . error ( "Error updating ringtone count:" , error ) ;
85- }
80+ // Increment the ringtone count in Redis
81+ async function incrementRingtoneCount ( ) {
82+ try {
83+ await fetch ( ` ${ REDIS_URL } /incr/ringtone_count` , { headers : { Authorization : `Bearer ${ REDIS_TOKEN } ` } } ) ;
84+ updateRingtoneCount ( ) ;
85+ } catch ( error ) {
86+ console . error ( "Error updating ringtone count:" , error ) ;
8687 }
88+ }
8789
88- async function processRingtone ( ) {
89- const urlInput = document . getElementById ( "youtube-url" ) . value ;
90- const androidLink = document . getElementById ( "android-ringtone" ) ;
91- const iphoneLink = document . getElementById ( "iphone-ringtone" ) ;
92- const status = document . getElementById ( "status" ) ;
93- const ringtoneContainer = document . getElementById ( "ringtone-container" ) ;
90+ // Function to process ringtone creation
91+ async function processRingtone ( ) {
92+ const urlInput = document . getElementById ( "youtube-url" ) . value ;
93+ const androidLink = document . getElementById ( "android-ringtone" ) ;
94+ const iphoneLink = document . getElementById ( "iphone-ringtone" ) ;
95+ const status = document . getElementById ( "status" ) ;
96+ const ringtoneContainer = document . getElementById ( "ringtone-container" ) ;
97+
98+ if ( ! urlInput ) {
99+ status . innerText = "Please enter a valid YouTube URL." ;
100+ return ;
101+ }
94102
95- if ( ! urlInput ) {
96- status . innerText = "Please enter a valid YouTube URL." ;
97- return ;
98- }
103+ try {
104+ status . innerText = "⏳ Just a moment..." ;
99105
100- try {
101- status . innerText = "⏳ Just a moment..." ;
102- const client = await import ( "https://cdn.jsdelivr.net/npm/@gradio/client/+esm" ) . then ( ( m ) => m . Client ) ;
103- const connectedClient = await client . connect ( "sudo-soldier/PYTR" ) ;
106+ const client = await import ( "https://cdn.jsdelivr.net/npm/@gradio/client/+esm" ) . then ( ( m ) => m . Client ) ;
107+ const connectedClient = await client . connect ( "sudo-soldier/PYTR" ) ;
104108
105- const timeoutPromise = new Promise ( ( _ , reject ) =>
106- setTimeout ( ( ) => reject ( new Error ( "Connection timed out!" ) ) , 36000 )
107- ) ;
109+ const timeoutPromise = new Promise ( ( _ , reject ) =>
110+ setTimeout ( ( ) => reject ( new Error ( "Connection timed out!" ) ) , 36000 )
111+ ) ;
108112
113+ const result = await Promise . race ( [
114+ connectedClient . predict ( "/process_youtube_or_audio" , { url : urlInput , start_time : 0 , end_time : 20 } ) ,
115+ timeoutPromise ,
116+ ] ) ;
109117
110- const result = await Promise . race ( [
111- connectedClient . predict ( "/process_youtube_or_audio" , { url : urlInput } ) ,
112- timeoutPromise ,
113- ] ) ;
118+ const androidFile = result ?. data ?. [ 0 ] ?. url || result ?. data ?. [ 0 ] ?. path ;
119+ const iphoneFile = result ?. data ?. [ 1 ] ?. url || result ?. data ?. [ 1 ] ?. path ;
114120
115- const androidFile = result . data [ 0 ] ?. url || result . data [ 0 ] ?. path ;
116- const iphoneFile = result . data [ 1 ] ?. url || result . data [ 1 ] ?. path ;
121+ if ( androidFile ) {
122+ androidLink . href = androidFile ;
123+ androidLink . download = "android_ringtone.mp3" ;
124+ androidLink . style . display = "block" ;
125+ }
117126
118- if ( androidFile ) {
119- androidLink . href = androidFile ;
120- androidLink . download = "android_ringtone.mp3 " ;
121- androidLink . style . display = "block" ;
122- }
127+ if ( iphoneFile ) {
128+ iphoneLink . href = iphoneFile ;
129+ iphoneLink . download = "iphone_ringtone.m4r " ;
130+ iphoneLink . style . display = "block" ;
131+ }
123132
124- if ( iphoneFile ) {
125- iphoneLink . href = iphoneFile ;
126- iphoneLink . download = "iphone_ringtone.m4r" ;
127- iphoneLink . style . display = "block" ;
133+ status . innerText = "Ringtone ready for download!" ;
134+ ringtoneContainer . classList . add ( "glow-border" ) ;
135+ incrementRingtoneCount ( ) ;
136+ } catch ( error ) {
137+ console . error ( "Error processing ringtone:" , error ) ;
138+ status . innerText = `Error: ${ error . message || "An unexpected error occurred!" } ` ;
139+ }
128140 }
129141
130- status . innerText = "Ringtone ready for download!" ;
131- ringtoneContainer . classList . add ( "glow-border" ) ;
132- incrementRingtoneCount ( ) ;
133- } catch ( error ) {
134- console . error ( "Error processing ringtone:" , error ) ;
135- status . innerText = `Error: ${ error . message || "An unexpected error occurred!" } ` ;
136- }
137- }
138-
139- async function pasteClipboard ( ) {
140- try {
141- const text = await navigator . clipboard . readText ( ) ;
142- document . getElementById ( "youtube-url" ) . value = text ;
143- } catch ( error ) {
144- console . error ( "Failed to read clipboard:" , error ) ;
145- }
142+ // Function to paste clipboard content into the URL input
143+ async function pasteClipboard ( ) {
144+ try {
145+ const text = await navigator . clipboard . readText ( ) ;
146+ document . getElementById ( "youtube-url" ) . value = text ;
147+ } catch ( error ) {
148+ console . error ( "Failed to read clipboard:" , error ) ;
146149 }
150+ }
147151
148- updateRingtoneCount ( ) ;
149- </ script >
150- </ body >
152+ // Initial count fetch
153+ updateRingtoneCount ( ) ;
154+ </ script >
155+ </ body >
151156</ html >
152-
153-
154-
155-
156-
157-
158-
159-
160-
161-
162-
163-
164-
165-
166-
167-
168-
169-
170-
171-
172-
0 commit comments