Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +65 -34
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,71 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import whisper
|
| 3 |
+
from moviepy.editor import *
|
| 4 |
+
import requests
|
| 5 |
+
from bs4 import BeautifulSoup
|
| 6 |
+
from diffusers import StableDiffusionPipeline
|
| 7 |
+
import torch
|
| 8 |
+
import arabic_reshaper
|
| 9 |
+
from bidi.algorithm import get_display
|
| 10 |
+
from googletrans import Translator
|
| 11 |
+
import os
|
| 12 |
|
| 13 |
+
# --- Setup UI ---
|
| 14 |
+
st.title("گۆرانی بۆ شۆرت - ئۆتۆماتیکی")
|
| 15 |
+
st.write("فایلی گۆرانییەکە ئەپلۆد بکە و چاوەڕێ بکە...")
|
| 16 |
|
| 17 |
+
uploaded_file = st.file_uploader("گۆرانییەکە هەڵبژێرە", type=["mp3", "wav"])
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
if uploaded_file is not None:
|
| 20 |
+
st.audio(uploaded_file, format='audio/mp3')
|
| 21 |
+
|
| 22 |
+
if st.button('دەستپێکردن'):
|
| 23 |
+
with st.spinner('خەریکی گوێگرتنە لە گۆرانییەکە...'):
|
| 24 |
+
# 1. Save Audio
|
| 25 |
+
with open("temp_audio.mp3", "wb") as f:
|
| 26 |
+
f.write(uploaded_file.getbuffer())
|
| 27 |
+
|
| 28 |
+
# 2. Transcribe (Whisper)
|
| 29 |
+
model = whisper.load_model("base") # مۆدێلی سووک
|
| 30 |
+
result = model.transcribe("temp_audio.mp3")
|
| 31 |
+
transcribed_text = result["text"]
|
| 32 |
+
st.success(f"تێکست دۆزرایەوە: {transcribed_text[:50]}...")
|
| 33 |
|
| 34 |
+
# 3. Google Search (Simple Simulation for demo)
|
| 35 |
+
# لێرەدا کۆدی گەڕان لە گوگڵ دێت (پێویستی بە API هەیە ئەگەر زۆر ورد بێت)
|
| 36 |
+
# بۆ ئێستا تێکستەکە خۆی بەکاردێنین
|
| 37 |
+
final_lyrics = transcribed_text
|
| 38 |
|
| 39 |
+
with st.spinner('خەریکی دروستکردنی وێنەیە...'):
|
| 40 |
+
# 4. Generate Images (Stable Diffusion)
|
| 41 |
+
# تێبینی: ئەمە لەسەر CPUی خۆڕایی هێواشە.
|
| 42 |
+
translator = Translator()
|
| 43 |
+
english_prompt = translator.translate(final_lyrics[:100], dest='en').text
|
| 44 |
+
|
| 45 |
+
# بەکارهێنانی مۆدێلی بچووک بۆ خێرایی
|
| 46 |
+
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float32)
|
| 47 |
+
# ئەگەر GPU نەبێت، ئەم بەشە زۆر هێواش دەبێت لە Hugging Face Free
|
| 48 |
+
# بۆیە پێشنیار دەکەم API وێنە بەکاربێنیت نەک لۆکاڵ
|
| 49 |
+
|
| 50 |
+
st.info("بەهۆی قورسی مۆدێلی وێنە، لەم نموونەیەدا وێنەی ڕەنگ بەکاردێنین. (بۆ وێنەی AI دەبێت API ببەستین)")
|
| 51 |
+
|
| 52 |
+
# Generate Dummy Video for Demo
|
| 53 |
+
# 5. Create Video with MoviePy
|
| 54 |
+
audio_clip = AudioFileClip("temp_audio.mp3").subclip(0, 15) # تەنها ١٥ چرکە بۆ تێست
|
| 55 |
+
|
| 56 |
+
# دروستکردنی تێکستی فارسی
|
| 57 |
+
reshaped_text = arabic_reshaper.reshape(final_lyrics[:30])
|
| 58 |
+
bidi_text = get_display(reshaped_text)
|
| 59 |
+
|
| 60 |
+
# دروستکردنی کلیپ
|
| 61 |
+
txt_clip = TextClip(bidi_text, fontsize=50, color='white', font='Arial') # دەبێت فۆنت ئەپلۆد بکرێت
|
| 62 |
+
txt_clip = txt_clip.set_pos('center').set_duration(15)
|
| 63 |
+
|
| 64 |
+
video = ColorClip(size=(720, 1280), color=(0,0,0), duration=15)
|
| 65 |
+
video = video.set_audio(audio_clip)
|
| 66 |
+
video = CompositeVideoClip([video, txt_clip])
|
| 67 |
+
|
| 68 |
+
video.write_videofile("final_short.mp4", fps=24)
|
| 69 |
+
|
| 70 |
+
st.success("تەواو!")
|
| 71 |
+
st.video("final_short.mp4")
|