Spaces:
Runtime error
Runtime error
File size: 1,888 Bytes
c5bdd8b |
1 2 3 4 5 6 7 8 9 10 11 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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
@app.get("/")
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()
|