Spaces:
Running
Running
File size: 3,636 Bytes
4cd8188 9a90ff3 4cd8188 9a90ff3 5467d69 4cd8188 6b4c8c0 5467d69 4cd8188 9a90ff3 0cfc66a 9a90ff3 4cd8188 9a90ff3 4cd8188 9a90ff3 4cd8188 9a90ff3 4cd8188 9a90ff3 4cd8188 9a90ff3 0cfc66a 9a90ff3 0cfc66a 9a90ff3 4cd8188 9a90ff3 4cd8188 9a90ff3 |
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 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 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
import gradio as gr
import emoji
import random
class MemeAgent:
def __init__(self):
model = HfApiModel('mistralai/Mistral-7B-Instruct-v0.1')
self.agent = CodeAgent(
model=model,
tools=[DuckDuckGoSearchTool()]
)
self.styles = {
"sarcastic": self._sarcastic_style,
"vibe": self._vibe_style,
"dramatic": self._dramatic_style,
"uwu": self._uwu_style,
"gamer": self._gamer_style,
"deep": self._deep_style,
"cool": self._cool_style
}
def _sarcastic_style(self, text):
return "".join(c.upper() if i % 2 else c.lower() for i, c in enumerate(text)) + " 🥴"
def _vibe_style(self, text):
return "✨ " + " ✨ ".join(text.split()) + " ✨"
def _dramatic_style(self, text):
return f"😔✋ {text} 😭💔"
def _uwu_style(self, text):
text = text.replace('r', 'w').replace('l', 'w')
return f"{text} uwu 🥺👉👈"
def _gamer_style(self, text):
return f"🎮 {text.replace('o', '0').replace('a', '4')} GG! 🎯"
def _deep_style(self, text):
return f"🌌 {text} 💭✨ #deep #mindblown"
def _cool_style(self, text):
return f"😎 {text} 🔥"
def process_text(self, text, style=None):
if not text.strip():
return "Por favor, ingresa algún texto", "No hay texto para procesar"
# Usar el agente para analizar el texto y sugerir un estilo si no se proporciona uno
if not style:
prompt = f"""
Analiza este texto: '{text}'
Selecciona el mejor estilo de meme entre estas opciones: {list(self.styles.keys())}
Solo responde con el nombre del estilo, nada más.
"""
style = self.agent.run(prompt).strip().lower()
if style not in self.styles:
style = random.choice(list(self.styles.keys()))
explanation = f"El agente eligió el estilo '{style}' basado en el análisis del texto."
else:
explanation = f"Usando el estilo '{style}' como solicitaste."
converted_text = self.styles[style](text)
return converted_text, explanation
def create_interface():
agent = MemeAgent()
def process_input(text, style=None):
return agent.process_text(text, style)
iface = gr.Interface(
fn=process_input,
inputs=[
gr.Textbox(
label="Ingresa tu texto",
placeholder="Escribe algo para convertir en meme..."
),
gr.Dropdown(
choices=[""] + list(agent.styles.keys()), # Agregamos una opción vacía
label="Estilo de meme (opcional)",
value="" # Establecemos string vacío como valor por defecto
)
],
outputs=[
gr.Textbox(label="Texto convertido"),
gr.Textbox(label="Explicación")
],
title="🎭 Convertidor de Memes con IA",
description="Convierte texto normal en diferentes estilos de memes usando IA",
examples=[
["la vida es bella", "dramatic"],
["me encanta programar"],
["soy un profesional", "sarcastic"],
["victoria royale", "gamer"],
["estoy pensando en el universo", "deep"]
],
theme="huggingface"
)
return iface
if __name__ == "__main__":
demo = create_interface()
demo.launch()
|