Spaces:
Sleeping
Sleeping
Deploy Gradio app with multiple files
Browse files- app.py +102 -0
- requirements.txt +24 -0
app.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def generate_video(prompt, duration, progress=gr.Progress()):
|
| 5 |
+
"""Generate video using akhaliq-Sora-2 API"""
|
| 6 |
+
if not prompt.strip():
|
| 7 |
+
raise gr.Error("Please enter a text prompt")
|
| 8 |
+
|
| 9 |
+
progress(0.1, desc="Starting video generation...")
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
# API endpoint for akhaliq-Sora-2
|
| 13 |
+
api_url = "https://akhaliq-sora-2.hf.space/api/predict"
|
| 14 |
+
|
| 15 |
+
# Prepare the payload
|
| 16 |
+
payload = {
|
| 17 |
+
"data": [
|
| 18 |
+
prompt, # text prompt
|
| 19 |
+
duration, # duration in seconds
|
| 20 |
+
30, # fps (fixed)
|
| 21 |
+
512, # width (fixed)
|
| 22 |
+
512, # height (fixed)
|
| 23 |
+
]
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
progress(0.5, desc="Generating video...")
|
| 27 |
+
|
| 28 |
+
# Make the API request
|
| 29 |
+
response = requests.post(api_url, json=payload)
|
| 30 |
+
|
| 31 |
+
if response.status_code == 200:
|
| 32 |
+
progress(0.9, desc="Processing...")
|
| 33 |
+
result = response.json()
|
| 34 |
+
|
| 35 |
+
# Check if the generation is complete
|
| 36 |
+
if "data" in result and len(result["data"]) > 0:
|
| 37 |
+
video_url = result["data"][0]
|
| 38 |
+
if video_url:
|
| 39 |
+
progress(1.0, desc="Complete!")
|
| 40 |
+
return video_url
|
| 41 |
+
else:
|
| 42 |
+
raise gr.Error("Video generation failed")
|
| 43 |
+
else:
|
| 44 |
+
raise gr.Error("Invalid response from API")
|
| 45 |
+
else:
|
| 46 |
+
raise gr.Error(f"API request failed with status code: {response.status_code}")
|
| 47 |
+
|
| 48 |
+
except requests.exceptions.RequestException as e:
|
| 49 |
+
raise gr.Error(f"Network error: {str(e)}")
|
| 50 |
+
except Exception as e:
|
| 51 |
+
raise gr.Error(f"Error generating video: {str(e)}")
|
| 52 |
+
|
| 53 |
+
# Create the Gradio interface
|
| 54 |
+
with gr.Blocks(title="Text-to-Video AI Generator") as demo:
|
| 55 |
+
|
| 56 |
+
gr.Markdown("# 🎬 Text-to-Video AI Generator")
|
| 57 |
+
gr.Markdown("Transform your text into AI-generated videos using Sora-2 model")
|
| 58 |
+
gr.Markdown('<p><a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a></p>')
|
| 59 |
+
|
| 60 |
+
with gr.Row():
|
| 61 |
+
with gr.Column():
|
| 62 |
+
prompt_input = gr.Textbox(
|
| 63 |
+
label="Video Description",
|
| 64 |
+
placeholder="Describe the video you want to generate...",
|
| 65 |
+
lines=3
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
duration_slider = gr.Slider(
|
| 69 |
+
minimum=1,
|
| 70 |
+
maximum=10,
|
| 71 |
+
value=4,
|
| 72 |
+
step=1,
|
| 73 |
+
label="Video Duration (seconds)"
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
generate_btn = gr.Button("Generate Video", variant="primary")
|
| 77 |
+
|
| 78 |
+
with gr.Column():
|
| 79 |
+
video_output = gr.Video(
|
| 80 |
+
label="Generated Video",
|
| 81 |
+
height=400
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
gr.Examples(
|
| 85 |
+
examples=[
|
| 86 |
+
["A cat playing piano", 4],
|
| 87 |
+
["A robot dancing", 6],
|
| 88 |
+
["A sunset over the ocean", 3],
|
| 89 |
+
],
|
| 90 |
+
inputs=[prompt_input, duration_slider]
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
generate_btn.click(
|
| 94 |
+
fn=generate_video,
|
| 95 |
+
inputs=[prompt_input, duration_slider],
|
| 96 |
+
outputs=[video_output],
|
| 97 |
+
show_progress=True
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# Launch the app
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
requests
|
| 2 |
+
gradio
|
| 3 |
+
Pillow
|
| 4 |
+
numpy
|
| 5 |
+
scipy
|
| 6 |
+
joblib
|
| 7 |
+
pandas
|
| 8 |
+
openpyxl
|
| 9 |
+
matplotlib
|
| 10 |
+
torch
|
| 11 |
+
torchvision
|
| 12 |
+
torchaudio
|
| 13 |
+
accelerate
|
| 14 |
+
tokenizers
|
| 15 |
+
datasets
|
| 16 |
+
uvicorn
|
| 17 |
+
pydantic
|
| 18 |
+
streamlit
|
| 19 |
+
opencv-python
|
| 20 |
+
python-docx
|
| 21 |
+
PyPDF2
|
| 22 |
+
git+https://github.com/huggingface/transformers
|
| 23 |
+
sentencepiece
|
| 24 |
+
git+https://github.com/huggingface/diffusers
|