Hamodc / app.py
mohamedshawkat654's picture
Update app.py
29fd6d7 verified
Raw
History Blame Contribute Delete
748 Bytes
import gradio as gr
from gradio_client import Client
import base64
from io import BytesIO
def generate_base64(prompt):
# بنكلم الموديل الأصلي وبناخد الصورة
client = Client("black-forest-labs/FLUX.1-schnell")
result = client.predict(prompt=prompt, seed=0, randomize_seed=True, width=1024, height=1024, num_inference_steps=4, api_name="/predict")
# تحويل الصورة لكود نصي عشان نهرب من الـ CORS والـ Abort
with open(result, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
return f"data:image/png;base64,{encoded_string}"
demo = gr.Interface(fn=generate_base64, inputs="text", outputs="text")
demo.launch()