Spaces:
Runtime error
Runtime error
from fastapi import FastAPI | |
import fal_client | |
import gradio as gr | |
import threading | |
import os | |
from pathlib import Path | |
from public_instagram_loader import public_instagram_loader, InstagramData | |
app = FastAPI() | |
# Set up the FAL API Key | |
FAL_KEY = os.getenv("FAL_KEY") | |
#fal_client.set_api_key(FAL_KEY) | |
# FastAPI route | |
def greet_json(): | |
return {"AI-InstagramPhotos": "Generate photos from your favorite Instagram account using FAL API."} | |
# Function to submit Instagram data to FAL API | |
def submit_to_fal(instagram_data: InstagramData): | |
handler = fal_client.submit( | |
"fal-ai/flux-lora-fast-training", | |
arguments={ | |
"images_data_url": instagram_data.image_urls, | |
"trigger_word": instagram_data.profile_info['username'], | |
"is_style": True | |
}, | |
) | |
result = handler.get() | |
return result | |
# Gradio interface for interacting with the Instagram loader and FAL | |
def gradio_interface(): | |
def generate_lora_from_instagram(username: str): | |
# Load Instagram data | |
instagram_data = public_instagram_loader(username) | |
if instagram_data is None: | |
return "Profile not found or an error occurred." | |
# Pass Instagram data to FAL API for LoRA training | |
fal_result = submit_to_fal(instagram_data) | |
# Return the URL of the trained LoRA weights | |
return f"Trained LoRA weights: {fal_result['diffusers_lora_file']['url']}" | |
iface = gr.Interface( | |
fn=generate_lora_from_instagram, | |
inputs=gr.Textbox(label="Enter Instagram username"), | |
outputs=gr.Textbox(label="LoRA URL"), | |
title="Instagram LoRA Generator using FAL" | |
) | |
# Launch Gradio on a different port (7861) | |
iface.launch(server_name="0.0.0.0", server_port=7861) | |
# Run Gradio in a separate thread | |
thread = threading.Thread(target=gradio_interface) | |
thread.start() | |