Spaces:
Sleeping
Sleeping
Commit
·
d127a39
1
Parent(s):
a2c85d2
MegoFlow UI – replace old interface
Browse files
app.py
CHANGED
|
@@ -1,173 +1,113 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from actora import ActoraPredictor, emoji_map as actora_emoji_map
|
| 4 |
-
import warnings
|
| 5 |
warnings.filterwarnings("ignore", category=UserWarning)
|
| 6 |
-
import logging
|
| 7 |
logging.getLogger("transformers").setLevel(logging.ERROR)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
emoji_map_svg = {
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
'support': "data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cg clip-path='url(%23clip0_15251_63610)'%3E%3Cpath d='M15.9982 7.9998c0 4.4181-3.5815 7.9996-7.9996 7.9996-4.418 0-7.9996-3.5815-7.9996-7.9996 0-4.418 3.5816-7.9996 7.9996-7.9996 4.4181 0 7.9996 3.5816 7.9996 7.9996Z' fill='url(%23paint0_linear_15251_63610)'/%3E%3Cpath d='M15.9973 7.9992c0 4.4178-3.5811 7.9992-7.9987 7.9992C3.5811 15.9984 0 12.417 0 7.9992S3.5811 0 7.9986 0c4.4176 0 7.9987 3.5814 7.9987 7.9992Z' fill='url(%23paint1_radial_15251_63610)'/%3E%3Cmask id='mask0_15251_63610' style='mask-type:alpha' maskUnits='userSpaceOnUse' x='6' y='13' width='8' height='3'%3E%3Cpath d='M13.6084 13.7029c-1.4438 1.4203-3.4244 2.2965-5.6097 2.2965a8.0393 8.0393 0 0 1-1.5715-.1543c.6898-.2867 1.6353-.7368 2.5437-1.3171 1.2793.5295 3.4828.2415 4.6285-.8326l.009.0075Z' fill='%23D9D9D9'/%3E%3C/mask%3E%3Cg mask='url(%23mask0_15251_63610)'%3E%3Cpath d='M15.9982 7.9998c0 4.4181-3.5815 7.9996-7.9996 7.9996-4.418 0-7.9996-3.5815-7.9996-7.9996 0-4.418 3.5816-7.9996 7.9996-7.9996 4.4181 0 7.9996 3.5816 7.9996 7.9996Z' fill='url(%23paint2_linear_15251_63610)'/%3E%3C/g%3E%3Cpath d='M15.9962 7.9996c0 4.418-3.5815 7.9996-7.9995 7.9996S-.003 12.4176-.003 7.9996 3.5786 0 7.9967 0c4.418 0 7.9995 3.5815 7.9995 7.9996Z' fill='url(%23paint3_radial_15251_63610)'/%3E%3Cpath d='M15.9962 7.9996c0 4.418-3.5815 7.9996-7.9995 7.9996S-.003 12.4176-.003 7.9996 3.5786 0 7.9967 0c4.418 0 7.9995 3.5815 7.9995 7.9996Z' fill='url(%23paint4_radial_15251_63610)'/%3E%3Cpath d='M15.9962 7.9996c0 4.418-3.5815 7.9996-7.9995 7.9996S-.003 12.4176-.003 7.9996 3.5786 0 7.9967 0c4.418 0 7.9995 3.5815 7.9995 7.9996Z' fill='url(%23paint5_radial_15251_63610)' style='mix-blend-mode:multiply'/%3E%3Cpath d='M15.9962 7.9996c0 4.418-3.5815 7.9996-7.9995 7.9996S-.003 12.4176-.003 7.9996 3.5786 0 7.9967 0c4.418 0 7.9995 3.5815 7.9995 7.9996Z' fill='url(%23paint6_radial_15251_63610)' style='mix-blend-mode:multiply'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M9.585 7.7886a.499.499 0 0 1 .026.0043 2.849 2.849 0 0 1 1.8175 1.202 2.8423 2.8423 0 0 1 .4349 2.1333c-.2461 1.2665-1.3291 2.3137-2.4304 3.0886-1.1259.7923-2.3926 1.3839-3.2016 1.7072a1.08 1.08 0 0 1-1.151-.2237c-.6289-.6028-1.5818-1.6259-2.329-2.7823-.7307-1.131-1.3425-2.5076-1.0963-3.7741a2.8425 2.8425 0 0 1 1.2024-1.8151 2.8492 2.8492 0 0 1 2.1354-.4336.5086.5086 0 0 1 .0268.006 2.9735 2.9735 0 0 1 1.4594.8686c.1647.1788.3813.4853.5716.8626.3155-.2781.6296-.482.8526-.5874a2.9734 2.9734 0 0 1 1.6817-.2564Z' fill='url(%23paint7_radial_15251_63610)'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M9.585 7.7886a.499.499 0 0 1 .026.0043 2.849 2.849 0 0 1 1.8175 1.202 2.8423 2.8423 0 0 1 .4349 2.1333c-.2461 1.2665-1.3291 2.3137-2.4304 3.0886-1.1259.7923-2.3926 1.3839-3.2016 1.7072a1.08 1.08 0 0 1-1.151-.2237c-.6289-.6028-1.5818-1.6259-2.329-2.7823-.7307-1.131-1.3425-2.5076-1.0963-3.7741a2.8425 2.8425 0 0 1 1.2024-1.8151 2.8492 2.8492 0 0 1 2.1354-.4336.5086.5086 0 0 1 .0268.006 2.9735 2.9735 0 0 1 1.4594.8686c.1647.1788.3813.4853.5716.8626.3155-.2781.6296-.482.8526-.5874a2.9734 2.9734 0 0 1 1.6817-.2564Z' fill='url(%23paint8_radial_15251_63610)'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M9.585 7.7886a.499.499 0 0 1 .026.0043 2.849 2.849 0 0 1 1.8175 1.202 2.8423 2.8423 0 0 1 .4349 2.1333c-.2461 1.2665-1.3291 2.3137-2.4304 3.0886-1.1259.7923-2.3926 1.3839-3.2016 1.7072a1.08 1.08 0 0 1-1.151-.2237c-.6289-.6028-1.5818-1.6259-2.329-2.7823-.7307-1.131-1.3425-2.5076-1.0963-3.7741a2.8425 2.8425 0 0 1 1.2024-1.8151 2.8492 2.8492 0 0 1 2.1354-.4336.5086.5086 0 0 1 .0268.006 2.9735 2.9735 0 0 1 1.4594.8686c.1647.1788.3813.4853.5716.8626.3155-.2781.6296-.482.8526-.5874a2.9734 2.9734 0 0 1 1.6817-.2564Z' fill='url(%23paint9_radial_15251_63610)'/%3E%3Cmask id='mask1_15251_63610' style='mask-type:alpha' maskUnits='userSpaceOnUse' x='-1' y='0' width='17' height='16'%3E%3Ccircle cx='7.9976' cy='7.9998' r='7.9996' fill='%23fff'/%3E%3C/mask%3E%3Cg mask='url(%23mask1_15251_63610)' fill-rule='evenodd' clip-rule='evenodd'%3E%3Cpath d='M1.3582 7.6194C.836 7.1064.318 7.2994.118 7.9596c-.2.6603-.0513 2.4955 1.0427 3.3962 2.752 2.2662 5.464.8613 5.5191-.5247.0498-1.2472-1.3555-1.113-1.8127-1.0879-.0311.0018-.0445-.0412-.0178-.0582.096-.0626.2535-.1719.4198-.3125.3594-.3044.1753-.8326-.3264-.6813-.0756.0224-1.2968.3904-2.0707.0967-.8778-.3331-.9828-.6465-1.5147-1.1685h.0009Z' fill='%23FFF287'/%3E%3Cpath d='M1.3582 7.6194C.836 7.1064.318 7.2994.118 7.9596c-.2.6603-.0513 2.4955 1.0427 3.3962 2.752 2.2662 5.464.8613 5.5191-.5247.0498-1.2472-1.3555-1.113-1.8127-1.0879-.0311.0018-.0445-.0412-.0178-.0582.096-.0626.2535-.1719.4198-.3125.3594-.3044.1753-.8326-.3264-.6813-.0756.0224-1.2968.3904-2.0707.0967-.8778-.3331-.9828-.6465-1.5147-1.1685h.0009Z' fill='url(%23paint10_linear_15251_63610)'/%3E%3Cpath d='M1.3582 7.6194C.836 7.1064.318 7.2994.118 7.9596c-.2.6603-.0513 2.4955 1.0427 3.3962 2.752 2.2662 5.464.8613 5.5191-.5247.0498-1.2472-1.3555-1.113-1.8127-1.0879-.0311.0018-.0445-.0412-.0178-.0582.096-.0626.2535-.1719.4198-.3125.3594-.3044.1753-.8326-.3264-.6813-.0756.0224-1.2968.3904-2.0707.0967-.8778-.3331-.9828-.6465-1.5147-1.1685h.0009Z' fill='url(%23paint11_radial_15251_63610)' fill-opacity='.6'/%3E%3Cpath d='M1.3582 7.6194C.836 7.1064.318 7.2994.118 7.9596c-.2.6603-.0513 2.4955 1.0427 3.3962 2.752 2.2662 5.464.8613 5.5191-.5247.0498-1.2472-1.3555-1.113-1.8127-1.0879-.0311.0018-.0445-.0412-.0178-.0582.096-.0626.2535-.1719.4198-.3125.3594-.3044.1753-.8326-.3264-.6813-.0756.0224-1.2968.3904-2.0707.0967-.8778-.3331-.9828-.6465-1.5147-1.1685h.0009Z' fill='url(%23paint12_radial_15251_63610)'/%3E%3Cpath d='M1.3582 7.6194C.836 7.1064.318 7.2994.118 7.9596c-.2.6603-.0513 2.4955 1.0427 3.3962 2.752 2.2662 5.464.8613 5.5191-.5247.0498-1.2472-1.3555-1.113-1.8127-1.0879-.0311.0018-.0445-.0412-.0178-.0582.096-.0626.2535-.1719.4198-.3125.3594-.3044.1753-.8326-.3264-.6813-.0756.0224-1.2968.3904-2.0707.0967-.8778-.3331-.9828-.6465-1.5147-1.1685h.0009Z' fill='url(%23paint13_radial_15251_63610)'/%3E%3Cpath d='M1.3582 7.6194C.836 7.1064.318 7.2994.118 7.9596c-.2.6603-.0513 2.4955 1.0427 3.3962 2.752 2.2662 5.464.8613 5.5191-.5247.0498-1.2472-1.3555-1.113-1.8127-1.0879-.0311.0018-.0445-.0412-.0178-.0582.096-.0626.2535-.1719.4198-.3125.3594-.3044.1753-.8326-.3264-.6813-.0756.0224-1.2968.3904-2.0707.0967-.8778-.3331-.9828-.6465-1.5147-1.1685h.0009Z' fill='url(%23paint14_radial_15251_63610)'/%3E%3Cpath d='M14.2827 7.7582c.3146-.7585.3146-1.1585.7145-1.3585.4-.2 1 .4 1 1.6 0 1.9998-.8 4.1957-2.3999 5.6956-1.5999 1.5-5.2626 1.4668-5.5906-.1845-.2727-1.3695 1.1697-1.5059 1.6332-1.571.0316-.0045.0378-.0542.0079-.0677a4.201 4.201 0 0 1-.474-.262c-.4125-.2647-.3176-.8871.211-.8203.599.0913 1.3395.2647 1.978.1997 1.8469-.1888 2.6052-2.4728 2.9199-3.2313Z' fill='%23FFF287'/%3E%3Cpath d='M14.2827 7.7582c.3146-.7585.3146-1.1585.7145-1.3585.4-.2 1 .4 1 1.6 0 1.9998-.8 4.1957-2.3999 5.6956-1.5999 1.5-5.2626 1.4668-5.5906-.1845-.2727-1.3695 1.1697-1.5059 1.6332-1.571.0316-.0045.0378-.0542.0079-.0677a4.201 4.201 0 0 1-.474-.262c-.4125-.2647-.3176-.8871.211-.8203.599.0913 1.3395.2647 1.978.1997 1.8469-.1888 2.6052-2.4728 2.9199-3.2313Z' fill='url(%23paint15_linear_15251_63610)'/%3E%3Cpath d='M14.2827 7.7582c.3146-.7585.3146-1.1585.7145-1.3585.4-.2 1 .4 1 1.6 0 1.9998-.8 4.1957-2.3999 5.6956-1.5999 1.5-5.2626 1.4668-5.5906-.1845-.2727-1.3695 1.1697-1.5059 1.6332-1.571.0316-.0045.0378-.0542.0079-.0677a4.201 4.201 0 0 1-.474-.262c-.4125-.2647-.3176-.8871.211-.8203.599.0913 1.3395.2647 1.978.1997 1.8469-.1888 2.6052-2.4728 2.9199-3.2313Z' fill='url(%23paint16_radial_15251_63610)' fill-opacity='.8'/%3E%3Cpath d='M14.2827 7.7582c.3146-.7585.3146-1.1585.7145-1.3585.4-.2 1 .4 1 1.6 0 1.9998-.8 4.1957-2.3999 5.6956-1.5999 1.5-5.2626 1.4668-5.5906-.1845-.2727-1.3695 1.1697-1.5059 1.6332-1.571.0316-.0045.0378-.0542.0079-.0677a4.201 4.201 0 0 1-.474-.262c-.4125-.2647-.3176-.8871.211-.8203.599.0913 1.3395.2647 1.978.1997 1.8469-.1888 2.6052-2.4728 2.9199-3.2313Z' fill='url(%23paint17_radial_15251_63610)'/%3E%3Cpath d='M14.2827 7.7582c.3146-.7585.3146-1.1585.7145-1.3585.4-.2 1 .4 1 1.6 0 1.9998-.8 4.1957-2.3999 5.6956-1.5999 1.5-5.2626 1.4668-5.5906-.1845-.2727-1.3695 1.1697-1.5059 1.6332-1.571.0316-.0045.0378-.0542.0079-.0677a4.201 4.201 0 0 1-.474-.262c-.4125-.2647-.3176-.8871.211-.8203.599.0913 1.3395.2647 1.978.1997 1.8469-.1888 2.6052-2.4728 2.9199-3.2313Z' fill='url(%23paint18_radial_15251_63610)' fill-opacity='.9' style='mix-blend-mode:screen'/%3E%3C/g%3E%3Cpath d='M7.9977 6.8c.71 0 1.1723-.1164 1.4952-.2331.3063-.1108.4-.4145.08-.4762C9.277 6.0336 8.7886 6 7.9978 6c-.7753 0-1.2813.0342-1.5903.0988-.3085.0646-.2235.3583.073.4654.3257.1177.8017.2357 1.5173.2357Z' fill='%234B280E'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M10.1526 2.0928a3.3945 3.3945 0 0 1 2.0299.699.4.4 0 0 0 .4863-.6352 4.1946 4.1946 0 0 0-2.5083-.8637.4.4 0 1 0-.0079.7999ZM5.843 2.0928a3.3946 3.3946 0 0 0-2.03.699.4.4 0 1 1-.4862-.6352 4.1945 4.1945 0 0 1 2.5083-.8637.4.4 0 1 1 .008.7999Z' fill='%23E0761A'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M9.998 4.3577c-.001.7238.483.936 1.1999 1.023.7099.1024 1.1878-.1978 1.1998-1.023.01-.6941-.3809-1.5413-1.1998-1.5575-.8189.0162-1.1999.8634-1.1999 1.5575ZM5.998 4.3577c.001.7238-.483.936-1.1998 1.023-.71.1024-1.1879-.1978-1.1999-1.023-.01-.6941.381-1.5413 1.1999-1.5575.8189.0162 1.1998.8634 1.1998 1.5575Z' fill='%231C1C1D'/%3E%3C/g%3E%3Cdefs%3E%3CradialGradient id='paint1_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(0 7.9992 -7.99863 0 7.9986 7.9992)'%3E%3Cstop offset='.5637' stop-color='%23FF5758' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23FF5758' stop-opacity='.1'/%3E%3C/radialGradient%3E%3CradialGradient id='paint3_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(.1233 -1.60292 4.45604 .34277 10.6837 13.9363)'%3E%3Cstop stop-color='%23791119' stop-opacity='.7'/%3E%3Cstop offset='1' stop-color='%23791119' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint4_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(.92919 2.03556 -13.3287 6.08424 12.9748 11.0609)'%3E%3Cstop stop-color='%23791119' stop-opacity='.08'/%3E%3Cstop offset='1' stop-color='%23791119' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint5_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(.5 -2 2.8733 .71832 3 11)'%3E%3Cstop offset='.2088' stop-color='%23791119' stop-opacity='.4'/%3E%3Cstop offset='1' stop-color='%23791119' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint6_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(1.5 -1 1.43665 2.15497 2 10)'%3E%3Cstop offset='.2088' stop-color='%23791119' stop-opacity='.3'/%3E%3Cstop offset='1' stop-color='%23791119' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint7_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(4.40005 5.20005 -6.1455 5.20005 4.198 9.4003)'%3E%3Cstop offset='.3729' stop-color='%23FA2E3E'/%3E%3Cstop offset='.9266' stop-color='%23E11731'/%3E%3C/radialGradient%3E%3CradialGradient id='paint8_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='rotate(-92.693 7.5086 3.7543) scale(1.72921 2.52467)'%3E%3Cstop stop-color='%23791119' stop-opacity='.9'/%3E%3Cstop offset='1' stop-color='%23791119' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint9_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='rotate(-65.627 15.8732 -.8589) scale(1.94093 2.8338)'%3E%3Cstop stop-color='%23791119' stop-opacity='.9'/%3E%3Cstop offset='1' stop-color='%23791119' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint11_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='rotate(93.472 -1.1146 5.8598) scale(4.00047 8.84233)'%3E%3Cstop stop-color='%23FFF287' stop-opacity='0'/%3E%3Cstop offset='.9846' stop-color='%23FF5758' stop-opacity='.8'/%3E%3C/radialGradient%3E%3CradialGradient id='paint12_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='rotate(131.396 1.7386 3.9605) scale(7.98139 8.42047)'%3E%3Cstop offset='.6481' stop-color='%23FFE480'/%3E%3Cstop offset='.9167' stop-color='%23FFE480' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint13_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='rotate(115.036 -.1572 5.1636) scale(5.20766 4.5125)'%3E%3Cstop offset='.9124' stop-color='%23FFE480' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23FFE480'/%3E%3C/radialGradient%3E%3CradialGradient id='paint14_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(1.35706 1.5577 -3.27818 2.85593 0 7.5)'%3E%3Cstop stop-color='%23FFE483'/%3E%3Cstop offset='.9167' stop-color='%23FFEB80' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint16_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='rotate(38.267 -7.741 22.3658) scale(3.94718 18.9414)'%3E%3Cstop stop-color='%23FFF287' stop-opacity='0'/%3E%3Cstop offset='.7371' stop-color='%23FF5758' stop-opacity='.4'/%3E%3C/radialGradient%3E%3CradialGradient id='paint17_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(2.93607 2.57398 -2.89968 3.3076 10.5 8)'%3E%3Cstop offset='.8254' stop-color='%23FFE480'/%3E%3Cstop offset='1' stop-color='%23FFE480' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='paint18_radial_15251_63610' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='matrix(4.5 2.5 -3.1886 5.73949 11 9)'%3E%3Cstop offset='.897' stop-color='%23FFE480' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23FFE480'/%3E%3C/radialGradient%3E%3ClinearGradient id='paint0_linear_15251_63610' x1='2.5019' y1='2.5002' x2='16.002' y2='16.0002' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='.2619' stop-color='%23FFF287'/%3E%3Cstop offset='1' stop-color='%23F68628'/%3E%3C/linearGradient%3E%3ClinearGradient id='paint2_linear_15251_63610' x1='10' y1='14.5002' x2='10' y2='17.0002' gradientUnits='userSpaceOnUse'%3E%3Cstop stop-color='%23FFF287' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23FFF287'/%3E%3C/linearGradient%3E%3ClinearGradient id='paint10_linear_15251_63610' x1='4.4115' y1='6.5983' x2='2.6271' y2='9.9854' gradientUnits='userSpaceOnUse'%3E%3Cstop stop-color='%23FFF287'/%3E%3Cstop offset='1' stop-color='%23F68628' stop-opacity='.3'/%3E%3C/linearGradient%3E%3ClinearGradient id='paint15_linear_15251_63610' x1='7.9727' y1='12.4766' x2='18.4483' y2='13.8876' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='.0835' stop-color='%23FFF287'/%3E%3Cstop offset='1' stop-color='%23F68628'/%3E%3C/linearGradient%3E%3CclipPath id='clip0_15251_63610'%3E%3Cpath fill='%23fff' d='M-.002.0002h16.0001v16h-16z'/%3E%3C/clipPath%3E%3C/defs%3E%3C/svg%3E",
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
'interactions': "data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1.5 8C1.5 4.9625 4.025 2.5 7.1875 2.5C8.84375 2.5 10.375 3.2375 11.4563 4.4125C12.5375 5.5875 13.1875 7.175 13.1875 8.8625C13.1875 11.1625 12.1125 13.15 10.5125 14.375C8.9125 15.6 6.8875 16 4.79375 15.5375C2.7 15.075 1.5 13.2937 1.5 11.1625' stroke='%2365676B' stroke-width='1.5' stroke-miterlimit='10' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M7.99961 14.8333C7.62461 14.8333 7.24961 14.8333 6.87461 14.8333C6.49961 14.8333 6.12461 14.8333 5.74961 14.8333' stroke='%2365676B' stroke-width='1.5' stroke-miterlimit='10' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M7.99961 1.16669C7.62461 1.16669 7.24961 1.16669 6.87461 1.16669C6.49961 1.16669 6.12461 1.16669 5.74961 1.16669' stroke='%2365676B' stroke-width='1.5' stroke-miterlimit='10' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M1.16699 7.99999C1.16699 7.62499 1.16699 7.24999 1.16699 6.87499C1.16699 6.49999 1.16699 6.12499 1.16699 5.74999' stroke='%2365676B' stroke-width='1.5' stroke-miterlimit='10' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M14.833 7.99999C14.833 7.62499 14.833 7.24999 14.833 6.87499C14.833 6.49999 14.833 6.12499 14.833 5.74999' stroke='%2365676B' stroke-width='1.5' stroke-miterlimit='10' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"
|
| 26 |
}
|
| 27 |
|
| 28 |
-
def
|
| 29 |
-
|
| 30 |
-
return emoji_preds
|
| 31 |
|
| 32 |
-
def
|
| 33 |
if not post_text.strip():
|
| 34 |
-
return "<div style='text-align:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
<
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
)
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
<span style="font-size:15px; color:#65676B;">{shares_val} مشاركة</span>
|
| 114 |
-
"""
|
| 115 |
-
|
| 116 |
-
html_content += f"""
|
| 117 |
-
</div>
|
| 118 |
-
</div>
|
| 119 |
-
|
| 120 |
-
<div style="padding-top:10px; display:flex; justify-content:space-around; align-items:center; font-weight:bold; color:#65676B; border-top:1px solid #f0f2f5;">
|
| 121 |
-
<div style="display:flex; align-items:center; gap:5px; cursor:pointer; padding:5px 10px; border-radius:6px; transition:background-color 0.2s ease;" onmouseover="this.style.backgroundColor='#e0e2e5';" onmouseout="this.style.backgroundColor='transparent';">
|
| 122 |
-
<img src="{emoji_map_svg['liked']}" style="width:24px; height:24px; vertical-align:middle;"/>
|
| 123 |
-
<span>إعجاب</span>
|
| 124 |
-
</div>
|
| 125 |
-
<div style="display:flex; align-items:center; gap:5px; cursor:pointer; padding:5px 10px; border-radius:6px; transition:background-color 0.2s ease;" onmouseover="this.style.backgroundColor='#e0e2e5';" onmouseout="this.style.backgroundColor='transparent';">
|
| 126 |
-
<img src="{emoji_map_svg['comments']}" style="width:24px; height:24px; vertical-align:middle;"/>
|
| 127 |
-
<span>تعليق</span>
|
| 128 |
-
</div>
|
| 129 |
-
<div style="display:flex; align-items:center; gap:5px; cursor:pointer; padding:5px 10px; border-radius:6px; transition:background-color 0.2s ease;" onmouseover="this.style.backgroundColor='#e0e2e5';" onmouseout="this.style.backgroundColor='transparent';">
|
| 130 |
-
<img src="{emoji_map_svg['shares']}" style="width:24px; height:24px; vertical-align:middle;"/>
|
| 131 |
-
<span>مشاركة</span>
|
| 132 |
-
</div>
|
| 133 |
-
</div>
|
| 134 |
-
</div>
|
| 135 |
-
"""
|
| 136 |
-
return html_content
|
| 137 |
-
|
| 138 |
-
iface = gr.Interface(
|
| 139 |
-
fn=create_post_html_interface,
|
| 140 |
-
inputs=gr.Textbox(
|
| 141 |
-
lines=5,
|
| 142 |
-
label="اكتب منشورك هنا",
|
| 143 |
-
placeholder="ما الذي يدور في ذهنك؟",
|
| 144 |
-
value="مرحبا بكم في تجربة حية لنموذج AcTora",
|
| 145 |
-
elem_id="post-input-textbox"
|
| 146 |
-
),
|
| 147 |
-
outputs=gr.HTML(
|
| 148 |
-
label="معاينة المنشور وتوقعات التفاعلات",
|
| 149 |
-
elem_id="post-output-html"
|
| 150 |
-
),
|
| 151 |
-
title="توقع تفاعلات المنشورات",
|
| 152 |
-
description="أدخل نص منشور لتوقع تفاعلاته (مثل الإعجابات والتعليقات والمشاركات).",
|
| 153 |
-
live=False,
|
| 154 |
-
allow_flagging="never",
|
| 155 |
-
css="""
|
| 156 |
-
#post-output-html iframe {
|
| 157 |
-
overflow: hidden !important;
|
| 158 |
-
}
|
| 159 |
-
#post-input-textbox textarea {
|
| 160 |
-
min-height: 100px !important;
|
| 161 |
-
}
|
| 162 |
-
.gradio-container {
|
| 163 |
-
max-width: 800px;
|
| 164 |
-
margin: auto;
|
| 165 |
-
}
|
| 166 |
-
.gr-button.gr-button-primary {
|
| 167 |
-
background-color: #0866FF !important;
|
| 168 |
-
border-color: #0866FF !important;
|
| 169 |
-
}
|
| 170 |
-
"""
|
| 171 |
-
)
|
| 172 |
-
|
| 173 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from actora import ActoraPredictor, emoji_map as actora_emoji_map
|
| 4 |
+
import warnings, logging
|
| 5 |
warnings.filterwarnings("ignore", category=UserWarning)
|
|
|
|
| 6 |
logging.getLogger("transformers").setLevel(logging.ERROR)
|
| 7 |
|
| 8 |
+
# تشغيل على GPU لو متاح
|
| 9 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
|
| 11 |
+
# مستودع النموذج (خلفية فقط – لا يظهر في الواجهة)
|
| 12 |
+
MODEL_REPO = "amrtweg/Actora"
|
| 13 |
|
| 14 |
+
# مهيّئ التنبؤ
|
| 15 |
+
predictor = ActoraPredictor(model_name_or_path=MODEL_REPO, device=DEVICE)
|
| 16 |
+
|
| 17 |
+
# أيقونات SVG (مصادر محلية داخل السطر – لا تعتمد على الواجهة الأصلية)
|
| 18 |
emoji_map_svg = {
|
| 19 |
+
"liked": "data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='8' fill='%230866FF'/%3E%3Cpath d='M7.2 3.2c0-.44.36-.8.8-.8.74 0 1.34.6 1.34 1.34v1.86h1.76c.96 0 1.66.9 1.44 1.86l-.45 1.88a2.2 2.2 0 0 1-2.14 1.69H6.9a.55.55 0 0 1-.55-.55V7.9c0-.4.09-.8.27-1.16l.27-.55c.27-.55.41-1.16.41-1.77V3.2ZM3.7 7.05c-.42 0-.76.34-.76.76v3.2c0 .42.34.76.76.76h.76c.2 0 .37-.17.37-.37V7.42c0-.2-.17-.37-.37-.37H3.7Z' fill='%23fff'/%3E%3C/svg%3E",
|
| 20 |
+
"loved": "data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='8' fill='%23FA2E3E'/%3E%3Cpath d='M8 11.1c2.1-1.43 3.9-2.67 3.9-4.36 0-.97-.73-1.92-1.82-1.92-.74 0-1.37.47-1.64 1.14-.27-.67-.9-1.14-1.64-1.14-1.09 0-1.82.95-1.82 1.92 0 1.7 1.8 2.94 3.9 4.36Z' fill='%23fff'/%3E%3C/svg%3E",
|
| 21 |
+
"haha": "data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='8' fill='%23F6A623'/%3E%3Ccircle cx='5.2' cy='5.6' r='1' fill='%231C1C1D'/%3E%3Ccircle cx='10.8' cy='5.6' r='1' fill='%231C1C1D'/%3E%3Cpath d='M4.6 9.6c.5 1.1 1.9 1.7 3.4 1.7s2.9-.6 3.4-1.7c.1-.3-.1-.6-.5-.6H5c-.4 0-.6.3-.4.6Z' fill='%231C1C1D'/%3E%3C/svg%3E",
|
| 22 |
+
"wow": "data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='8' fill='%23FFB169'/%3E%3Ccircle cx='5.3' cy='5.6' r='1.2' fill='%231C1C1D'/%3E%3Ccircle cx='10.7' cy='5.6' r='1.2' fill='%231C1C1D'/%3E%3Ccircle cx='8' cy='10.2' r='1.6' fill='%231C1C1D'/%3E%3C/svg%3E",
|
| 23 |
+
"sad": "data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='8' fill='%237A7F85'/%3E%3Ccircle cx='5.3' cy='6.1' r='.9' fill='%23fff'/%3E%3Ccircle cx='10.7' cy='6.1' r='.9' fill='%23fff'/%3E%3Cpath d='M5 11c.8-1 2-1.4 3-1.4s2.2.4 3 1.4' stroke='%23fff' stroke-width='1.2'/%3E%3C/svg%3E",
|
| 24 |
+
"angry":"data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='8' fill='%23E11731'/%3E%3Cpath d='M5 6l2 1M11 6l-2 1' stroke='%23fff' stroke-width='1.2'/%3E%3Cpath d='M5 11c1-.6 2-.8 3-.8s2 .2 3 .8' stroke='%23fff' stroke-width='1.2'/%3E%3C/svg%3E",
|
| 25 |
+
"shares":"data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M10.6 4.7 14 8l-3.4 3.3M14 8H2' stroke='%2365676B' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E",
|
| 26 |
+
"comments":"data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 14.5c-.6 0-1.2-.1-1.7-.3-.5-.2-1-.4-1.4-.7L1.5 15l.7-3.8C1.7 10.7 1.1 9.6 1.1 8.4c0-3 2.2-5.4 6-5.4 3 0 5.8 2 6.2 5 .2 1.2 0 2.4-.6 3.4-.6.9-1.5 1.6-2.6 1.9-.8.2-1.6.3-2.3.3Z' stroke='%2365676B' stroke-width='1.4'/%3E%3C/svg%3E",
|
| 27 |
+
"interactions":"data:image/svg+xml,%3Csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8a6 6 0 1 1 9.4 4.8' stroke='%2365676B' stroke-width='1.2'/%3E%3Cpath d='M8 15H5' stroke='%2365676B' stroke-width='1.2'/%3E%3Cpath d='M8 1H5' stroke='%2365676B' stroke-width='1.2'/%3E%3C/svg%3E",
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
+
def predict(text: str):
|
| 31 |
+
return predictor.predict(text)
|
|
|
|
| 32 |
|
| 33 |
+
def render_preview(post_text: str) -> str:
|
| 34 |
if not post_text.strip():
|
| 35 |
+
return "<div style='text-align:center;color:#9aa0a6'>اكتب منشورك في الصندوق على اليسار ثم اضغط «توقّع».</div>"
|
| 36 |
+
|
| 37 |
+
raw = predictor.predict(post_text)
|
| 38 |
+
# تحويل مفاتيح الايموجي الأصلية إلى أسماءنا
|
| 39 |
+
reverse_map = {v: k for k, v in actora_emoji_map.items()}
|
| 40 |
+
results = {reverse_map.get(k, k): v for k, v in raw.items()}
|
| 41 |
+
|
| 42 |
+
# ترتيب التفاعلات الإيجابية (بدون تعليقات/مشاركات/إجمالي)
|
| 43 |
+
rankables = {k: v for k, v in results.items() if k not in ["comments", "shares", "interactions"]}
|
| 44 |
+
sorted_pairs = sorted(rankables.items(), key=lambda x: x[1], reverse=True)
|
| 45 |
+
top3 = [(emoji_map_svg[k], v) for k, v in sorted_pairs[:3] if k in emoji_map_svg and v > 0]
|
| 46 |
+
|
| 47 |
+
comments = results.get("comments", 0)
|
| 48 |
+
shares = results.get("shares", 0)
|
| 49 |
+
|
| 50 |
+
total_positive = sum(v for _, v in rankables.items() if v > 0)
|
| 51 |
+
|
| 52 |
+
# بطاقة تصميم مختلفة تمامًا
|
| 53 |
+
html = [
|
| 54 |
+
"<div style='direction:rtl;font-family:Inter,Segoe UI,Arial,sans-serif;background:#0f1420;color:#e8eaed;border-radius:14px;overflow:hidden;border:1px solid #1f2937'>",
|
| 55 |
+
"<div style='background:linear-gradient(135deg,#0ea5e9,#6366f1);padding:14px 18px;display:flex;justify-content:space-between;align-items:center;'>",
|
| 56 |
+
"<div style='font-weight:800;font-size:18px;letter-spacing:.5px'>MegoFlow</div>",
|
| 57 |
+
"<div style='font-size:12px;opacity:.9'>Predict • Measure • Improve</div>",
|
| 58 |
+
"</div>",
|
| 59 |
+
f"<div style='padding:16px 18px;font-size:16px;line-height:1.7;color:#e5e7eb'>{post_text}</div>",
|
| 60 |
+
"<div style='padding:12px 18px;border-top:1px solid #1f2937;display:flex;justify-content:space-between;align-items:center;'>",
|
| 61 |
+
"<div style='display:flex;gap:6px;align-items:center'>"
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
for svg, _v in top3:
|
| 65 |
+
html.append(f"<img src='{svg}' style='width:20px;height:20px'/>")
|
| 66 |
+
|
| 67 |
+
if total_positive > 0:
|
| 68 |
+
html.append(f"<span style='color:#9aa0a6;font-size:14px'>+{total_positive}</span>")
|
| 69 |
+
|
| 70 |
+
html.append("</div><div style='display:flex;gap:14px;align-items:center'>")
|
| 71 |
+
if comments > 0:
|
| 72 |
+
html.append(f"<span style='color:#9aa0a6;font-size:14px'>{comments} تعليق</span>")
|
| 73 |
+
if shares > 0:
|
| 74 |
+
html.append(f"<span style='color:#9aa0a6;font-size:14px'>{shares} مشاركة</span>")
|
| 75 |
+
html.append("</div></div>") # end row
|
| 76 |
+
html.append("</div>") # end card
|
| 77 |
+
|
| 78 |
+
return "".join(html)
|
| 79 |
+
|
| 80 |
+
with gr.Blocks(css="""
|
| 81 |
+
:root { --mf-bg:#0b1020; --mf-panel:#0f1420; --mf-accent:#6366f1; --mf-accent2:#0ea5e9; }
|
| 82 |
+
.gradio-container { max-width: 980px; margin: 0 auto; }
|
| 83 |
+
.mf-wrap { display:grid; grid-template-columns: 1.1fr 0.9fr; gap:16px; }
|
| 84 |
+
.mf-panel { background: var(--mf-panel); border:1px solid #1f2937; border-radius:16px; padding:18px; color:#e8eaed; }
|
| 85 |
+
.mf-title { font-weight:800; font-size:20px; margin-bottom:14px; background: linear-gradient(135deg,var(--mf-accent2),var(--mf-accent)); -webkit-background-clip:text; -webkit-text-fill-color:transparent;}
|
| 86 |
+
.mf-btn > button { background: linear-gradient(135deg,var(--mf-accent2),var(--mf-accent)) !important; border:0 !important; }
|
| 87 |
+
""",
|
| 88 |
+
title="MegoFlow — توقع التفاعل من سلاسة النص",
|
| 89 |
+
theme=gr.themes.Soft()) as demo:
|
| 90 |
+
|
| 91 |
+
gr.Markdown("""<div style='text-align:center;margin:8px 0 2px'>
|
| 92 |
+
<span style='font-weight:800;font-size:24px;background:linear-gradient(135deg,#0ea5e9,#6366f1);-webkit-background-clip:text;-webkit-text-fill-color:transparent'>
|
| 93 |
+
MegoFlow
|
| 94 |
+
</span>
|
| 95 |
+
<div style='color:#9aa0a6'>أدخل نص المنشور، واضغط «توقّع» لتحصل على معاينة بتصميم مختلف وقياس للتفاعل المتوقع.</div>
|
| 96 |
+
</div>""")
|
| 97 |
+
|
| 98 |
+
with gr.Row(elem_classes="mf-wrap"):
|
| 99 |
+
with gr.Column(elem_classes="mf-panel"):
|
| 100 |
+
gr.Markdown("<div class='mf-title'>نص المنشور</div>")
|
| 101 |
+
txt = gr.Textbox(
|
| 102 |
+
lines=8,
|
| 103 |
+
placeholder="اكتب الكوبي هنا… (Hook → Body → CTA)",
|
| 104 |
+
label=None
|
| 105 |
+
)
|
| 106 |
+
btn = gr.Button("توقّع", elem_classes="mf-btn")
|
| 107 |
+
with gr.Column(elem_classes="mf-panel"):
|
| 108 |
+
gr.Markdown("<div class='mf-title'>المعاينة والتوقع</div>")
|
| 109 |
+
out = gr.HTML(label=None)
|
| 110 |
+
|
| 111 |
+
btn.click(render_preview, inputs=txt, outputs=out)
|
| 112 |
+
|
| 113 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|