Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,8 @@ def get_inference_client():
|
|
| 13 |
return InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 14 |
|
| 15 |
def extract_and_clean_json(text):
|
| 16 |
-
|
|
|
|
| 17 |
if json_match:
|
| 18 |
json_str = json_match.group()
|
| 19 |
json_str = re.sub(r'[\n\t\r]', '', json_str)
|
|
@@ -39,13 +40,11 @@ def generate_presentation_content(topic, client):
|
|
| 39 |
|
| 40 |
response = client.text_generation(prompt, max_new_tokens=1500, temperature=0.7)
|
| 41 |
|
| 42 |
-
# Mensaje de depuración para imprimir la respuesta original
|
| 43 |
st.text("Respuesta original del modelo:")
|
| 44 |
st.code(response)
|
| 45 |
-
|
| 46 |
json_str = extract_and_clean_json(response)
|
| 47 |
|
| 48 |
-
# Mensaje de depuración para imprimir el JSON después de la limpieza
|
| 49 |
st.text("JSON procesado (después de limpieza):")
|
| 50 |
st.code(json_str)
|
| 51 |
|
|
|
|
| 13 |
return InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 14 |
|
| 15 |
def extract_and_clean_json(text):
|
| 16 |
+
# Busca el JSON válido en el texto
|
| 17 |
+
json_match = re.search(r'\{(?:[^{}]|(?R))*\}', text, re.DOTALL)
|
| 18 |
if json_match:
|
| 19 |
json_str = json_match.group()
|
| 20 |
json_str = re.sub(r'[\n\t\r]', '', json_str)
|
|
|
|
| 40 |
|
| 41 |
response = client.text_generation(prompt, max_new_tokens=1500, temperature=0.7)
|
| 42 |
|
|
|
|
| 43 |
st.text("Respuesta original del modelo:")
|
| 44 |
st.code(response)
|
| 45 |
+
|
| 46 |
json_str = extract_and_clean_json(response)
|
| 47 |
|
|
|
|
| 48 |
st.text("JSON procesado (después de limpieza):")
|
| 49 |
st.code(json_str)
|
| 50 |
|