Spaces:
Sleeping
Sleeping
File size: 5,326 Bytes
c3c908f 0ede85b c3c908f 0ede85b c3c908f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
import gradio as gr
import torch
import librosa
import numpy as np
from inference import inference
def detect_ai_audio(audio_file):
"""
Detect whether the uploaded audio file was generated by AI
"""
result = inference(audio_file)
print(result)
# Format result with better styling
if "AI" in str(result).upper() or "artificial" in str(result).lower():
status = "AI Generated"
color = "#ff6b6b"
else:
status = "Human Generated"
color = "#51cf66"
formatted_result = f"""
<div style="text-align: center; padding: 20px; border-radius: 10px; background: linear-gradient(135deg, {color}22, {color}11);">
<div style="font-size: 24px; font-weight: bold; color: {color}; margin-bottom: 8px;">{status}</div>
<div style="font-size: 16px; color: #666;">Analysis Result: {result}</div>
</div>
"""
return formatted_result
# ์ปค์คํ
CSS
custom_css = """
/* ์ ์ฒด ๋ฐฐ๊ฒฝ ๊ทธ๋ผ๋์ธํธ */
.gradio-container {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
min-height: 100vh;
}
/* ๋ฉ์ธ ์ปจํ
์ด๋ ์คํ์ผ๋ง */
.main-container {
background: rgba(255, 255, 255, 0.95) !important;
backdrop-filter: blur(10px) !important;
border-radius: 20px !important;
box-shadow: 0 20px 40px rgba(0,0,0,0.1) !important;
margin: 20px !important;
padding: 30px !important;
}
/* ์ ๋ชฉ ์คํ์ผ๋ง */
h1 {
background: linear-gradient(135deg, #667eea, #764ba2) !important;
-webkit-background-clip: text !important;
-webkit-text-fill-color: transparent !important;
text-align: center !important;
font-size: 3em !important;
font-weight: 800 !important;
margin-bottom: 10px !important;
text-shadow: 2px 2px 4px rgba(0,0,0,0.1) !important;
}
/* ์ค๋ช
ํ
์คํธ */
.gradio-markdown p {
text-align: center !important;
font-size: 1.2em !important;
color: #555 !important;
margin-bottom: 30px !important;
}
/* ์ค๋์ค ์
๋ก๋ ์ปดํฌ๋ํธ */
.upload-container {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%) !important;
border-radius: 15px !important;
padding: 20px !important;
border: none !important;
box-shadow: 0 10px 30px rgba(240, 147, 251, 0.3) !important;
transition: all 0.3s ease !important;
}
.upload-container:hover {
transform: translateY(-5px) !important;
box-shadow: 0 15px 40px rgba(240, 147, 251, 0.4) !important;
}
/* ๊ฒฐ๊ณผ ์ถ๋ ฅ ์์ญ */
.output-container {
background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%) !important;
border-radius: 15px !important;
padding: 20px !important;
border: none !important;
box-shadow: 0 10px 30px rgba(168, 237, 234, 0.3) !important;
min-height: 150px !important;
}
/* ์์ ํ์ผ ์น์
*/
.examples-container {
background: rgba(255, 255, 255, 0.7) !important;
border-radius: 15px !important;
padding: 20px !important;
margin-top: 30px !important;
box-shadow: 0 5px 15px rgba(0,0,0,0.08) !important;
}
/* ๋ฒํผ ์คํ์ผ๋ง */
.gr-button {
background: linear-gradient(135deg, #667eea, #764ba2) !important;
border: none !important;
border-radius: 25px !important;
padding: 12px 30px !important;
font-weight: 600 !important;
color: white !important;
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4) !important;
transition: all 0.3s ease !important;
}
.gr-button:hover {
transform: translateY(-2px) !important;
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6) !important;
}
/* ์ ๋๋ฉ์ด์
์ถ๊ฐ */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.gradio-container > div {
animation: fadeInUp 0.8s ease-out !important;
}
/* ๋ฐ์ํ ๋์์ธ */
@media (max-width: 768px) {
h1 {
font-size: 2em !important;
}
.main-container {
margin: 10px !important;
padding: 20px !important;
}
}
"""
# Gradio ์ธํฐํ์ด์ค ์์ฑ
demo = gr.Interface(
fn=detect_ai_audio,
inputs=gr.Audio(
type="filepath",
label="Upload Audio File",
elem_classes=["upload-container"]
),
outputs=gr.HTML(
label="Detection Result",
elem_classes=["output-container"]
),
title="AI Audio Detector",
description="""
<div style="text-align: center; font-size: 1.2em; color: #555; margin: 20px 0;">
<p><strong>Advanced AI technology</strong> to accurately detect whether uploaded audio was generated by AI!</p>
<p>Supported formats: MP3, WAV, M4A, FLAC and various audio formats</p>
<p>Fast and accurate real-time analysis</p>
</div>
""",
examples=[
["example-ncs-light it up(human).mp3"],
["example-Strumming Heartbeats(suno v4).mp3"]
],
css=custom_css,
theme=gr.themes.Soft(
primary_hue="blue",
secondary_hue="purple",
neutral_hue="gray",
font=[gr.themes.GoogleFont("Inter"), "Arial", "sans-serif"]
),
elem_classes=["main-container"]
)
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=True,
show_api=False,
show_error=True
) |