services: FalImageGenService now uses fal-client library
This commit is contained in:
@@ -22,8 +22,7 @@ ELEVENLABS_API_KEY=...
|
|||||||
ELEVENLABS_VOICE_ID=...
|
ELEVENLABS_VOICE_ID=...
|
||||||
|
|
||||||
# Fal
|
# Fal
|
||||||
FAL_KEY_ID=...
|
FAL_KEY=...
|
||||||
FAL_KEY_SECRET=...
|
|
||||||
|
|
||||||
# PlayHT
|
# PlayHT
|
||||||
PLAY_HT_USER_ID=...
|
PLAY_HT_USER_ID=...
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ async def main(room_url):
|
|||||||
image_size="square_hd"
|
image_size="square_hd"
|
||||||
),
|
),
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
key_id=os.getenv("FAL_KEY_ID"),
|
key=os.getenv("FAL_KEY"),
|
||||||
key_secret=os.getenv("FAL_KEY_SECRET"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
pipeline = Pipeline([imagegen])
|
pipeline = Pipeline([imagegen])
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ async def main():
|
|||||||
image_size="square_hd"
|
image_size="square_hd"
|
||||||
),
|
),
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
key_id=os.getenv("FAL_KEY_ID"),
|
key=os.getenv("FAL_KEY"),
|
||||||
key_secret=os.getenv("FAL_KEY_SECRET"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
pipeline = Pipeline([imagegen])
|
pipeline = Pipeline([imagegen])
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ async def main(room_url):
|
|||||||
image_size="square_hd"
|
image_size="square_hd"
|
||||||
),
|
),
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
key_id=os.getenv("FAL_KEY_ID"),
|
key=os.getenv("FAL_KEY"),
|
||||||
key_secret=os.getenv("FAL_KEY_SECRET"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
gated_aggregator = GatedAggregator(
|
gated_aggregator = GatedAggregator(
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ async def main():
|
|||||||
image_size="1024x1024"
|
image_size="1024x1024"
|
||||||
),
|
),
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
key_id=os.getenv("FAL_KEY_ID"),
|
key=os.getenv("FAL_KEY"),
|
||||||
key_secret=os.getenv("FAL_KEY_SECRET"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get a complete audio chunk from the given text. Splitting this into its own
|
# Get a complete audio chunk from the given text. Splitting this into its own
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ async def main(room_url: str):
|
|||||||
image_size="1024x1024"
|
image_size="1024x1024"
|
||||||
),
|
),
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
key_id=os.getenv("FAL_KEY_ID"),
|
key=os.getenv("FAL_KEY"),
|
||||||
key_secret=os.getenv("FAL_KEY_SECRET"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
bot1_messages = [
|
bot1_messages = [
|
||||||
|
|||||||
@@ -208,8 +208,7 @@ async def main(room_url: str, token):
|
|||||||
image_size = "1024x1024",
|
image_size = "1024x1024",
|
||||||
},
|
},
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
key_id=os.getenv("FAL_KEY_ID"),
|
key=os.getenv("FAL_KEY"),
|
||||||
key_secret=os.getenv("FAL_KEY_SECRET"),
|
|
||||||
)
|
)
|
||||||
lra = LLMAssistantResponseAggregator(messages)
|
lra = LLMAssistantResponseAggregator(messages)
|
||||||
ura = LLMUserResponseAggregator(messages)
|
ura = LLMUserResponseAggregator(messages)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ anthropic = [ "anthropic~=0.20.0" ]
|
|||||||
azure = [ "azure-cognitiveservices-speech~=1.36.0" ]
|
azure = [ "azure-cognitiveservices-speech~=1.36.0" ]
|
||||||
daily = [ "daily-python~=0.7.0" ]
|
daily = [ "daily-python~=0.7.0" ]
|
||||||
examples = [ "python-dotenv~=1.0.0", "flask~=3.0.0", "flask_cors~=4.0.0" ]
|
examples = [ "python-dotenv~=1.0.0", "flask~=3.0.0", "flask_cors~=4.0.0" ]
|
||||||
fal = [ "fal~=0.12.0" ]
|
fal = [ "fal-client~=0.2.0" ]
|
||||||
local = [ "pyaudio~=0.2.0" ]
|
local = [ "pyaudio~=0.2.0" ]
|
||||||
moondream = [ "einops~=0.7.0", "timm~=0.9.0", "transformers~=4.39.0" ]
|
moondream = [ "einops~=0.7.0", "timm~=0.9.0", "transformers~=4.39.0" ]
|
||||||
openai = [ "openai~=1.14.0" ]
|
openai = [ "openai~=1.14.0" ]
|
||||||
|
|||||||
@@ -6,14 +6,15 @@ from PIL import Image
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import Optional, Union, Dict
|
from typing import Optional, Union, Dict
|
||||||
|
|
||||||
|
|
||||||
from dailyai.services.ai_services import ImageGenService
|
from dailyai.services.ai_services import ImageGenService
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import fal
|
import fal_client
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
print(f"Exception: {e}")
|
print(f"Exception: {e}")
|
||||||
print(
|
print(
|
||||||
"In order to use Fal, you need to `pip install dailyai[fal]`. Also, set `FAL_KEY_ID` and `FAL_KEY_SECRET` environment variables.")
|
"In order to use Fal, you need to `pip install dailyai[fal]`. Also, set `FAL_KEY` environment variable.")
|
||||||
raise Exception(f"Missing module: {e}")
|
raise Exception(f"Missing module: {e}")
|
||||||
|
|
||||||
|
|
||||||
@@ -33,40 +34,25 @@ class FalImageGenService(ImageGenService):
|
|||||||
aiohttp_session: aiohttp.ClientSession,
|
aiohttp_session: aiohttp.ClientSession,
|
||||||
params: InputParams,
|
params: InputParams,
|
||||||
model="fal-ai/fast-sdxl",
|
model="fal-ai/fast-sdxl",
|
||||||
key_id=None,
|
key=None,
|
||||||
key_secret=None
|
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._model = model
|
self._model = model
|
||||||
self._params = params
|
self._params = params
|
||||||
self._aiohttp_session = aiohttp_session
|
self._aiohttp_session = aiohttp_session
|
||||||
if key_id:
|
if key:
|
||||||
os.environ["FAL_KEY_ID"] = key_id
|
os.environ["FAL_KEY"] = key
|
||||||
if key_secret:
|
|
||||||
os.environ["FAL_KEY_SECRET"] = key_secret
|
|
||||||
|
|
||||||
async def run_image_gen(self, prompt: str) -> tuple[str, bytes, tuple[int, int]]:
|
async def run_image_gen(self, prompt: str) -> tuple[str, bytes, tuple[int, int]]:
|
||||||
def get_image_url(prompt):
|
response = await fal_client.run_async(
|
||||||
handler = fal.apps.submit( # type: ignore
|
self._model,
|
||||||
self._model,
|
arguments={"prompt": prompt, **self._params.dict()}
|
||||||
arguments={
|
)
|
||||||
"prompt": prompt,
|
|
||||||
**self._params.dict(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
for event in handler.iter_events():
|
|
||||||
if isinstance(event, fal.apps.InProgress): # type: ignore
|
|
||||||
pass
|
|
||||||
|
|
||||||
result = handler.get()
|
image_url = response["images"][0]["url"] if response else None
|
||||||
|
|
||||||
image_url = result["images"][0]["url"] if result else None
|
if not image_url:
|
||||||
if not image_url:
|
raise Exception("Image generation failed")
|
||||||
raise Exception("Image generation failed")
|
|
||||||
|
|
||||||
return image_url
|
|
||||||
|
|
||||||
image_url = await asyncio.to_thread(get_image_url, prompt)
|
|
||||||
|
|
||||||
# Load the image from the url
|
# Load the image from the url
|
||||||
async with self._aiohttp_session.get(image_url) as response:
|
async with self._aiohttp_session.get(image_url) as response:
|
||||||
|
|||||||
Reference in New Issue
Block a user