Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,11 @@ from gradio_client import Client
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
# ==============================================================================
|
| 9 |
-
#
|
|
|
|
| 10 |
# ==============================================================================
|
| 11 |
-
|
| 12 |
|
| 13 |
-
# HTML Content (Nano Banana's Design)
|
| 14 |
HTML_CONTENT = """
|
| 15 |
<!DOCTYPE html>
|
| 16 |
<html lang="my">
|
|
@@ -113,7 +113,7 @@ HTML_CONTENT = """
|
|
| 113 |
status.innerText = errText;
|
| 114 |
}
|
| 115 |
} catch (e) {
|
| 116 |
-
status.innerText = "Connection Error!
|
| 117 |
} finally {
|
| 118 |
btn.disabled = false;
|
| 119 |
btn.innerText = "Generate Voice";
|
|
@@ -137,32 +137,25 @@ def generate_voice(
|
|
| 137 |
pitch: int = Form(0)
|
| 138 |
):
|
| 139 |
try:
|
| 140 |
-
print(f"Connecting to Backend
|
| 141 |
|
| 142 |
-
#
|
| 143 |
-
|
| 144 |
-
# ==================================================================
|
| 145 |
-
client = Client(BACKEND_URL)
|
| 146 |
|
| 147 |
-
#
|
| 148 |
result = client.predict(
|
| 149 |
text,
|
| 150 |
tts_voice,
|
| 151 |
rvc_model,
|
| 152 |
-
pitch,
|
| 153 |
api_name="/convert_voice"
|
| 154 |
)
|
| 155 |
|
| 156 |
-
# Result
|
| 157 |
-
if not result:
|
| 158 |
-
return Response(content="Error: Backend မှ ဘာမှပြန်မလာပါ။", status_code=500)
|
| 159 |
-
|
| 160 |
-
# Result က Tuple ဖြစ်ကြောင်း သေချာအောင် စစ်မည်
|
| 161 |
if isinstance(result, tuple):
|
| 162 |
audio_path = result[0]
|
| 163 |
status_msg = result[1]
|
| 164 |
else:
|
| 165 |
-
# တခါတလေ List ပုံစံ ပြန်လာတတ်သည်
|
| 166 |
audio_path = result
|
| 167 |
status_msg = "Processed"
|
| 168 |
|
|
@@ -176,4 +169,5 @@ def generate_voice(
|
|
| 176 |
|
| 177 |
except Exception as e:
|
| 178 |
print(f"Critical Error: {e}")
|
|
|
|
| 179 |
return Response(content=f"System Error: {str(e)}", status_code=500)
|
|
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
# ==============================================================================
|
| 9 |
+
# ပြင်ဆင်ချက်: Space Name ကိုသာ သုံးပါ (URL မသုံးပါနဲ့)
|
| 10 |
+
# Token မထည့်ပါနဲ့ (Public Space မို့ Token ထည့်ရင် Permission Error တက်တတ်ပါတယ်)
|
| 11 |
# ==============================================================================
|
| 12 |
+
BACKEND_SPACE = "kochit/myanmar-rvc-tts"
|
| 13 |
|
|
|
|
| 14 |
HTML_CONTENT = """
|
| 15 |
<!DOCTYPE html>
|
| 16 |
<html lang="my">
|
|
|
|
| 113 |
status.innerText = errText;
|
| 114 |
}
|
| 115 |
} catch (e) {
|
| 116 |
+
status.innerText = "Connection Error!";
|
| 117 |
} finally {
|
| 118 |
btn.disabled = false;
|
| 119 |
btn.innerText = "Generate Voice";
|
|
|
|
| 137 |
pitch: int = Form(0)
|
| 138 |
):
|
| 139 |
try:
|
| 140 |
+
print(f"Connecting to Backend: {BACKEND_SPACE}...")
|
| 141 |
|
| 142 |
+
# Token မပါဘဲ ချိတ်ဆက်ပါ (Public Space မို့ ပိုအဆင်ပြေပါမယ်)
|
| 143 |
+
client = Client(BACKEND_SPACE)
|
|
|
|
|
|
|
| 144 |
|
| 145 |
+
# Pitch ကို float ပြောင်းပြီး ပို့ပါ
|
| 146 |
result = client.predict(
|
| 147 |
text,
|
| 148 |
tts_voice,
|
| 149 |
rvc_model,
|
| 150 |
+
float(pitch),
|
| 151 |
api_name="/convert_voice"
|
| 152 |
)
|
| 153 |
|
| 154 |
+
# Result Parsing
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
if isinstance(result, tuple):
|
| 156 |
audio_path = result[0]
|
| 157 |
status_msg = result[1]
|
| 158 |
else:
|
|
|
|
| 159 |
audio_path = result
|
| 160 |
status_msg = "Processed"
|
| 161 |
|
|
|
|
| 169 |
|
| 170 |
except Exception as e:
|
| 171 |
print(f"Critical Error: {e}")
|
| 172 |
+
# Error အစစ်အမှန်ကို မြင်ရအောင် ထုတ်ပြပါ
|
| 173 |
return Response(content=f"System Error: {str(e)}", status_code=500)
|