ilakurd commited on
Commit
d68e55b
·
verified ·
1 Parent(s): 66fcfe8

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Welcome to Streamlit!
 
8
 
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
 
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
 
 
18
 
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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")