File size: 4,410 Bytes
a1e0a61
 
 
 
ef6f36a
a1e0a61
 
 
 
 
 
 
 
 
 
4409e62
 
 
a1e0a61
 
4409e62
 
a1e0a61
4409e62
a1e0a61
 
 
4409e62
a1e0a61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8780939
a1e0a61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a36bc4
a1e0a61
 
 
0d3ee6a
ac26dea
a1e0a61
 
 
 
 
 
dbdd6c4
a1e0a61
 
 
 
dbdd6c4
a1e0a61
 
 
 
 
 
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
import os
import streamlit as st
import google.generativeai as genai

# TERMINATOR

error_flag = False  # Global variable to track error display

def generate_response(cleaned_input, model):
    global error_flag  # Use the global error_flag variable

    try:
        # Generate response using the model
        response = model.generate_content(cleaned_input, stream=True)

        # Ensure response iteration is complete before accessing accumulated attributes
        response.resolve()

        # Display the generated response
        full_response = ""
        for part in response.parts:  # Iterate through parts in multipart response
            full_response += part.text  # Use part.text to access the text of each part

        return full_response

    except Exception as e:
        error_message = str(e)
        if "text must be a valid text with a maximum of 5000 characters" in error_message and not error_flag:
            error_response = ("The question you are asking may go against Google GEMINI policies: WiseOracle"
                              "Please reformulate your question without forbidden topics or ask something else. "
                              "For more information, see: https://policies.google.com/terms/generative-ai/use-policy "
                             )
            st.error(error_response)
            error_flag = True  # Set the error_flag to True after displaying the error message
            return error_response
        else:
            error_response = f"Error: {error_message}\nSorry, I am an artificial intelligence that is still in development and is in alpha phase. At the moment, I cannot answer your question properly, but in the future, I will be able to do so."
            st.error(error_response)
            return error_response

# Aplicación Streamlit
def principal():
    st.title("Formateador de Entrevistas")

    genai.configure(api_key='AIzaSyA4k6JoFNZsf8L1ixLMMRjEMoBPns5SHZk')  # Replace with your Google GEMINI API key

    # Choose the Gemini model
    model = genai.GenerativeModel('gemini-pro')

    # Cargador de archivos para el archivo .txt
    archivo_cargado = st.file_uploader("Cargar un archivo .txt", type=["txt"])

    if archivo_cargado is not None:
        # Lee el contenido del archivo cargado
        contenido = archivo_cargado.read()

        # Botón para iniciar el formateo
        if st.button("Iniciar Formateo"):
            st.info("Formateo en progreso...")

            # Divide el contenido en chunks de 1500 palabras
            tamano_chunk = 1500
            chunks = [contenido[i:i + tamano_chunk] for i in range(0, len(contenido), tamano_chunk)]

            # Inicializa la barra de progreso
            barra_progreso_chunks = st.progress(0)

            # Procesa cada chunk y muestra la salida formateada
            salida_formateada = ""
            for i, chunk in enumerate(chunks):
                respuesta_bot = generate_response(
                    f" Lee atentamente el texto de la entrevista proporcionado y, siguiendo las indicaciones, formatea la salida como un segmento de entrevista con etiquetas de *Entrevistador:* y *Entrevistado:* precediendo cada línea, frase o párrafo según los roles identificados. Mantén el orden original del desarrollo del segmento de entrevista, añadiendo un salto de línea entre cada etiqueta y entre cada segmento. Asegúrate de corregir posibles palabras inentendibles, considerando el contexto global del párrafo. Procede de manera sistemática para garantizar que cada chunk procesado arroje exactamente el mismo resultado: {chunk}",
                    model
                )

                # Agrega la respuesta formateada a la salida
                salida_formateada += respuesta_bot + "\n"

                # Actualiza la barra de progreso
                barra_progreso_chunks.progress((i + 1) / len(chunks))

            # Muestra la salida formateada
            st.success("Formateo completado")
            st.text_area("Segmento de Entrevista Formateado:", salida_formateada)

            # Botón para descargar la respuesta formateada
            download_button = st.download_button(
                label="Descargar Respuesta",
                data=salida_formateada,
                file_name="respuesta_formateada.txt",
                key="download_button"
            )

if __name__ == "__main__":
    principal()