Spaces:
Build error
Build error
Upload app.py with huggingface_hub
Browse files12234515 unmodified lines2122232424252627108 unmodified lines136137138139140141139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172143144145173174175176177178179180181182183"""Movie Recap Backend - FastAPI + Gradio Application"""from fastapi import FastAPI, File, UploadFile, HTTPExceptionfrom fastapi import FastAPI, File, UploadFile, HTTPException, Formfrom fastapi.middleware.cors import CORSMiddlewareimport gradio as grimport os15 unmodified lines
app.add_middleware( CORSMiddleware, allow_origins=settings.CORS_ORIGINS, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"],108 unmodified lines uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860)))
# Gradio Interfacegradio_app = gr.Interface( fn=lambda video: "Gradio interface ready! Use /api/upload for video processing.",# Gradio Interface for HF Spacesdef generate_recap_interface(video, api_key): """Gradio interface function""" if not video: return "Please upload a video file." if not api_key: return "โ ๏ธ Please enter your OpenRouter API key.\n\nGet free key at: https://openrouter.ai/keys" try: # Process video processor = VideoProcessor(video) frames = processor.extract_key_frames() metadata = processor.get_metadata() # Generate recap import asyncio client = OpenRouterClient() recap = asyncio.run(client.generate_recap(frames, user_api_key=api_key)) result = f"๐น Video: {metadata['filename']}\n" result += f"โฑ๏ธ Duration: {metadata['duration']:.1f}s\n" result += f"๐ Resolution: {metadata['resolution']}\n\n" result += "=" * 50 + "\n\n" result += recap return result except Exception as e: return f"โ Error: {str(e)}"
# Build Gradio appdemo = gr.Interface( fn=generate_recap_interface, title="๐ฌ Movie Recap Generator", description="Upload a video to generate an AI-powered recap", inputs=gr.Video(label="Upload Video"), outputs=gr.Textbox(label="Recap Result") description="Upload a video and get an AI-powered movie recap. Enter your OpenRouter API key to use.", inputs=[ gr.Video(label="๐น Upload Video"), gr.Textbox(label="๐ OpenRouter API Key", placeholder="sk-or-v1-...", type="password") ], outputs=gr.Textbox(label="๐ Movie Recap", lines=15), allow_flagging="never")
# For HF Spaces with FastAPIapp = gr.mount_gradio_app(app, demo, path="/")app.py+45-8