Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ def get_inference_client():
|
|
| 13 |
return InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 14 |
|
| 15 |
def extract_and_clean_json(text):
|
| 16 |
-
json_match = re.search(r'\{.*\}', text, re.DOTALL)
|
| 17 |
if json_match:
|
| 18 |
json_str = json_match.group()
|
| 19 |
json_str = re.sub(r'[\n\t\r]', '', json_str)
|
|
@@ -24,12 +24,11 @@ def extract_and_clean_json(text):
|
|
| 24 |
|
| 25 |
def generate_presentation_content(topic, client):
|
| 26 |
prompt = f"""Crea una presentación de PowerPoint sobre el tema: {topic}.
|
| 27 |
-
Genera exactamente
|
| 28 |
1. Título de la presentación
|
| 29 |
2. Introducción
|
| 30 |
3. Índice
|
| 31 |
-
4-
|
| 32 |
-
8. Conclusiones
|
| 33 |
|
| 34 |
Formatea la salida como un JSON con la siguiente estructura:
|
| 35 |
{{
|
|
@@ -43,16 +42,16 @@ def generate_presentation_content(topic, client):
|
|
| 43 |
No incluyas saltos de línea o caracteres especiales dentro del JSON.
|
| 44 |
"""
|
| 45 |
|
| 46 |
-
response = client.text_generation(prompt, max_new_tokens=
|
| 47 |
|
| 48 |
try:
|
| 49 |
json_str = extract_and_clean_json(response)
|
| 50 |
if json_str:
|
| 51 |
slides_data = json.loads(json_str)
|
| 52 |
-
if 'slides' in slides_data and len(slides_data['slides']) ==
|
| 53 |
return slides_data['slides']
|
| 54 |
else:
|
| 55 |
-
raise ValueError("El JSON no contiene exactamente
|
| 56 |
else:
|
| 57 |
raise ValueError("No se encontró un JSON válido en la respuesta")
|
| 58 |
except json.JSONDecodeError as e:
|
|
@@ -69,48 +68,7 @@ def generate_presentation_content(topic, client):
|
|
| 69 |
return None
|
| 70 |
|
| 71 |
def apply_design(prs, design):
|
| 72 |
-
|
| 73 |
-
background = prs.slides[0].background
|
| 74 |
-
fill = background.fill
|
| 75 |
-
fill.solid()
|
| 76 |
-
fill.fore_color.rgb = RGBColor(240, 240, 240)
|
| 77 |
-
|
| 78 |
-
for slide in prs.slides:
|
| 79 |
-
for shape in slide.shapes:
|
| 80 |
-
if shape.has_text_frame:
|
| 81 |
-
tf = shape.text_frame
|
| 82 |
-
tf.text = tf.text
|
| 83 |
-
for paragraph in tf.paragraphs:
|
| 84 |
-
paragraph.font.color.rgb = RGBColor(0, 0, 0)
|
| 85 |
-
if shape.name == 'Title':
|
| 86 |
-
paragraph.font.size = Pt(44)
|
| 87 |
-
else:
|
| 88 |
-
paragraph.font.size = Pt(24)
|
| 89 |
-
elif design == "Corporativo":
|
| 90 |
-
background = prs.slides[0].background
|
| 91 |
-
fill = background.fill
|
| 92 |
-
fill.solid()
|
| 93 |
-
fill.fore_color.rgb = RGBColor(255, 255, 255)
|
| 94 |
-
|
| 95 |
-
for slide in prs.slides:
|
| 96 |
-
left = top = Inches(0.5)
|
| 97 |
-
width = Inches(1)
|
| 98 |
-
height = Inches(0.5)
|
| 99 |
-
shape = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, left, top, width, height)
|
| 100 |
-
shape.fill.solid()
|
| 101 |
-
shape.fill.fore_color.rgb = RGBColor(0, 112, 192)
|
| 102 |
-
|
| 103 |
-
for shape in slide.shapes:
|
| 104 |
-
if shape.has_text_frame:
|
| 105 |
-
tf = shape.text_frame
|
| 106 |
-
tf.text = tf.text
|
| 107 |
-
for paragraph in tf.paragraphs:
|
| 108 |
-
paragraph.font.color.rgb = RGBColor(0, 0, 0)
|
| 109 |
-
if shape.name == 'Title':
|
| 110 |
-
paragraph.font.size = Pt(40)
|
| 111 |
-
paragraph.font.color.rgb = RGBColor(0, 112, 192)
|
| 112 |
-
else:
|
| 113 |
-
paragraph.font.size = Pt(20)
|
| 114 |
|
| 115 |
def create_powerpoint(slides, design):
|
| 116 |
prs = Presentation()
|
|
|
|
| 13 |
return InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 14 |
|
| 15 |
def extract_and_clean_json(text):
|
| 16 |
+
json_match = re.search(r'\{.*?\}', text, re.DOTALL)
|
| 17 |
if json_match:
|
| 18 |
json_str = json_match.group()
|
| 19 |
json_str = re.sub(r'[\n\t\r]', '', json_str)
|
|
|
|
| 24 |
|
| 25 |
def generate_presentation_content(topic, client):
|
| 26 |
prompt = f"""Crea una presentación de PowerPoint sobre el tema: {topic}.
|
| 27 |
+
Genera exactamente 9 diapositivas con la siguiente estructura:
|
| 28 |
1. Título de la presentación
|
| 29 |
2. Introducción
|
| 30 |
3. Índice
|
| 31 |
+
4-9. Contenido principal (6 diapositivas)
|
|
|
|
| 32 |
|
| 33 |
Formatea la salida como un JSON con la siguiente estructura:
|
| 34 |
{{
|
|
|
|
| 42 |
No incluyas saltos de línea o caracteres especiales dentro del JSON.
|
| 43 |
"""
|
| 44 |
|
| 45 |
+
response = client.text_generation(prompt, max_new_tokens=2500, temperature=0.7)
|
| 46 |
|
| 47 |
try:
|
| 48 |
json_str = extract_and_clean_json(response)
|
| 49 |
if json_str:
|
| 50 |
slides_data = json.loads(json_str)
|
| 51 |
+
if 'slides' in slides_data and len(slides_data['slides']) == 9:
|
| 52 |
return slides_data['slides']
|
| 53 |
else:
|
| 54 |
+
raise ValueError(f"El JSON no contiene exactamente 9 diapositivas. Contiene {len(slides_data['slides'])} diapositivas.")
|
| 55 |
else:
|
| 56 |
raise ValueError("No se encontró un JSON válido en la respuesta")
|
| 57 |
except json.JSONDecodeError as e:
|
|
|
|
| 68 |
return None
|
| 69 |
|
| 70 |
def apply_design(prs, design):
|
| 71 |
+
# ... [El código de la función apply_design permanece igual] ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
def create_powerpoint(slides, design):
|
| 74 |
prs = Presentation()
|